Files
Alaister YoungandAlaister Young df798783e1 [FE-5108] (part 4) refactor(studio): migrate integrations, settings & observability off next/link (#54307)
Part 4 of a 6-PR stack migrating all `next/link` imports in
`apps/studio` onto TanStack Router's `Link` (or plain `<a>` for known
external URLs) and removing `compat/next/link.tsx`.

| Part | PR | Scope |
| --- | --- | --- |
| 1 | #54304 | `data/prefetchers/PrefetchableLink.tsx` and
`components/ui/**` |
| 2 | #54305 | `components/layouts/**` and top-level shell components |
| 3 | #54306 | Database, TableGridEditor, Storage, SQLEditor,
BranchManagement, Branching, Functions, Realtime |
| **4** | **#54307 ← this PR** | **Integrations, Settings,
Observability, LogDrains, Issues, Linter, Reports, QueryPerformance,
QuerySources, ConfigDrift, DiskManagement, Compute** |
| 5 | #54308 | Remaining `components/interfaces/**` (Org, Billing, Auth,
Support, Home, SignIn, ConnectSheet, etc.) |
| 6 | #54309 | Remove `compat/next/link.tsx` shim, Vite alias, and
update basePath tests/docs |

Migrates
`components/interfaces/{Integrations,Settings,Observability,LogDrains,Issues,Linter,Reports,QueryPerformance,QuerySources,ConfigDrift,DiskManagement,Compute}/`
off `next/link`.

**Changed:**

- Replaced `next/link` across all 72 files in Integrations, Settings,
Observability, LogDrains, Issues, Linter, Reports, QueryPerformance,
QuerySources, ConfigDrift, DiskManagement, and Compute interfaces
- Updated legacy permanent-redirect hrefs (`/settings/database` →
`/database/settings`, `/settings/vault/secrets` →
`/integrations/vault/secrets`, `/reports/database#database-size-report`
→ `/observability/database#database-size-report`) to canonical routes
- Flattened legacy nested `<Link><a>...</a></Link>` markup in
`DatabaseReadOnlyAlert.tsx` and dropped `passHref` in
`Integrations/Queues/QueueTab.tsx`
- Standardized external `target="_blank"` anchors with `rel="noreferrer
noopener"`, switched `ObservabilityOverviewFooter.tsx` to `InlineLink` +
`DOCS_URL`, and applied `InlineLinkClassName` to the typed billing links
in `DatabaseReadOnlyAlert.tsx` per review feedback
- Removed `vi.mock('next/link', ...)` from
`Settings/General/Project.test.tsx` and
`MobileIssuesNavigation.platform.test.tsx`

Addresses
[FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link)

## To test

- [ ] Navigate across Integrations (marketplace, cron, queues, wrappers,
Vercel/GitHub), Settings (database, infrastructure, read replicas,
logs), Observability, Issues, and Compute pages
- [ ] Verify Logs Preview → Logs Explorer links preserve multi-line SQL
queries in search params
- [ ] Verify billing and database-size links preserve query parameters
and hash fragments

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-12-01 17:02:11 +08:00

443 lines
18 KiB
TypeScript

import { zodResolver } from '@hookform/resolvers/zod'
import { Link } from '@tanstack/react-router'
import { useParams } from 'common'
import { capitalize } from 'lodash'
import { Fragment, useEffect } from 'react'
import { SubmitHandler, useForm, useWatch } from 'react-hook-form'
import { toast } from 'sonner'
import {
Alert,
AlertDescription,
AlertTitle,
Badge,
Button,
Form,
FormControl,
FormField,
FormInputGroupInput,
InputGroup,
InputGroupAddon,
InputGroupText,
Separator,
} from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import {
PageSection,
PageSectionAside,
PageSectionContent,
PageSectionMeta,
PageSectionSummary,
PageSectionTitle,
} from 'ui-patterns/PageSection'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import z from 'zod'
import { POOLING_OPTIMIZATIONS } from './ConnectionPooling.constants'
import { AlertError } from '@/components/ui/AlertError'
import { DocsButton } from '@/components/ui/DocsButton'
import { FormActions } from '@/components/ui/Forms/FormActions'
import { HighAvailabilityDisabledSectionNotice } from '@/components/ui/HighAvailability/HighAvailabilityDisabledSectionNotice'
import { InlineLink } from '@/components/ui/InlineLink'
import Panel from '@/components/ui/Panel'
import { useMaxConnectionsQuery } from '@/data/database/max-connections-query'
import { usePgbouncerConfigQuery } from '@/data/database/pgbouncer-config-query'
import { usePgbouncerConfigurationUpdateMutation } from '@/data/database/pgbouncer-config-update-mutation'
import { useProjectAddonsQuery } from '@/data/subscriptions/project-addons-query'
import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
import { useHighAvailability } from '@/hooks/misc/useHighAvailability'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import { useIsAwsCloudProvider, useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { DOCS_URL } from '@/lib/constants'
import { preprocessEmptyNumberInput } from '@/lib/forms/zod-number-input'
const formId = 'pooling-configuration-form'
const HIGH_AVAILABILITY_MAX_CLIENT_CONNECTIONS = 100_000
const HA_DISABLED_TITLE =
'Connection pooling settings are managed automatically on High Availability projects'
const PoolingConfigurationFormSchema = z.object({
default_pool_size: preprocessEmptyNumberInput(z.coerce.number().optional()),
max_client_conn: preprocessEmptyNumberInput(z.coerce.number().optional()),
})
/**
* [Joshen] PgBouncer configuration will be the main endpoint for GET and PATCH of pooling config
*/
export const ConnectionPooling = () => {
const { ref: projectRef } = useParams()
const isAws = useIsAwsCloudProvider()
const { data: project } = useSelectedProjectQuery()
const { isHighAvailability, isPending: isHighAvailabilityPending } = useHighAvailability()
const canLoadPoolingConfig = !isHighAvailability && !isHighAvailabilityPending
const { can: canUpdateConnectionPoolingConfiguration } = useAsyncCheckPermissionsV2(
FGA_PERMISSIONS.PROJECT.DATABASE_POOLING_CONFIG_WRITE
)
const { projectAddonsDedicatedIpv4Address } = useIsFeatureEnabled([
'project_addons:dedicated_ipv4_address',
])
const {
data: pgbouncerConfig,
error: pgbouncerConfigError,
isPending: isLoadingPgbouncerConfig,
isError: isErrorPgbouncerConfig,
isSuccess: isSuccessPgbouncerConfig,
} = usePgbouncerConfigQuery({ projectRef }, { enabled: canLoadPoolingConfig })
const { hasAccess: hasDedicatedPooler } = useCheckEntitlements('dedicated_pooler')
const disablePoolModeSelection = !hasDedicatedPooler
const { data: maxConnData } = useMaxConnectionsQuery(
{
projectRef: project?.ref,
connectionString: project?.connectionString,
},
{ enabled: canLoadPoolingConfig }
)
const { data: addons, isSuccess: isSuccessAddons } = useProjectAddonsQuery({ projectRef })
const { mutate: updatePoolerConfig, isPending: isUpdatingPoolerConfig } =
usePgbouncerConfigurationUpdateMutation()
const hasIpv4Addon = !!addons?.selected_addons.find((addon) => addon.type === 'ipv4')
const computeInstance = addons?.selected_addons.find((addon) => addon.type === 'compute_instance')
const computeSize =
computeInstance?.variant.name ?? capitalize(project?.infra_compute_size) ?? 'Nano'
const poolingOptimizations =
POOLING_OPTIMIZATIONS[
(computeInstance?.variant.identifier as keyof typeof POOLING_OPTIMIZATIONS) ??
(project?.infra_compute_size === 'nano' ? 'ci_nano' : 'ci_micro')
]
const defaultPoolSize = poolingOptimizations.poolSize ?? 15
const defaultMaxClientConn = poolingOptimizations.maxClientConn ?? 200
const form = useForm<z.infer<typeof PoolingConfigurationFormSchema>>({
resolver: zodResolver(PoolingConfigurationFormSchema),
defaultValues: {
default_pool_size: undefined,
max_client_conn: undefined,
},
})
const default_pool_size = useWatch({ control: form.control, name: 'default_pool_size' })
const connectionPoolingUnavailable = pgbouncerConfig?.pool_mode === null
const ignoreStartupParameters = pgbouncerConfig?.ignore_startup_parameters
const showIpv4Callout =
isAws &&
projectAddonsDedicatedIpv4Address &&
isSuccessAddons &&
!isHighAvailability &&
!disablePoolModeSelection &&
!hasIpv4Addon
const onSubmit: SubmitHandler<z.infer<typeof PoolingConfigurationFormSchema>> = async (data) => {
if (!projectRef || isHighAvailability) return
const { default_pool_size } = data
updatePoolerConfig(
{
ref: projectRef,
default_pool_size: default_pool_size === undefined ? null : default_pool_size,
ignore_startup_parameters: ignoreStartupParameters ?? '',
},
{
onSuccess: (data) => {
toast.success(`Successfully updated pooler configuration`)
if (data) {
form.reset({
default_pool_size: data.default_pool_size ?? undefined,
max_client_conn: data.max_client_conn ?? undefined,
})
}
},
}
)
}
const resetForm = () => {
form.reset({
default_pool_size: pgbouncerConfig?.default_pool_size ?? defaultPoolSize,
max_client_conn: pgbouncerConfig?.max_client_conn ?? defaultMaxClientConn,
})
}
useEffect(() => {
if (isSuccessPgbouncerConfig) resetForm()
}, [isSuccessPgbouncerConfig])
return (
<PageSection id="connection-pooler">
<PageSectionMeta>
<PageSectionSummary>
<PageSectionTitle>Connection pooling</PageSectionTitle>
</PageSectionSummary>
<PageSectionAside>
<DocsButton
href={`${DOCS_URL}/guides/database/connecting-to-postgres/pooling-and-limits#how-connection-pooling-works`}
/>
</PageSectionAside>
</PageSectionMeta>
<PageSectionContent className="space-y-4">
{isHighAvailability && (
<HighAvailabilityDisabledSectionNotice
title={HA_DISABLED_TITLE}
description={
<>
High Availability projects run one pooler per Postgres pod, each supporting up to{' '}
{HIGH_AVAILABILITY_MAX_CLIENT_CONNECTIONS.toLocaleString()} active or passive
connections, with pooling behavior selected automatically.{' '}
<InlineLink href="https://multigres.com/blog/pooling-without-choosing-a-mode">
Learn more
</InlineLink>
.
</>
}
/>
)}
{showIpv4Callout && (
<Admonition
type="default"
layout="responsive"
title="Dedicated pooler uses IPv6 by default"
description="Connections from IPv4-only networks require enabling the IPv4 add-on on your project instance."
actions={
<Button asChild>
<Link
to="/project/$ref/settings/addons"
params={{ ref: projectRef ?? '_' }}
search={{ panel: 'ipv4' }}
>
Enable IPv4 add-on
</Link>
</Button>
}
/>
)}
<Panel
noMargin
footer={
isHighAvailability ? undefined : (
<FormActions
form={formId}
isSubmitting={isUpdatingPoolerConfig}
hasChanges={form.formState.isDirty}
handleReset={() => resetForm()}
helper={
!canUpdateConnectionPoolingConfiguration
? 'You need additional permissions to update connection pooling settings'
: undefined
}
/>
)
}
>
<Panel.Content>
{!isHighAvailability && isLoadingPgbouncerConfig && (
<div className="flex flex-col gap-y-4">
{Array.from({ length: 4 }).map((_, i) => (
<Fragment key={`loader-${i}`}>
<div className="grid gap-2 items-center md:grid md:grid-cols-12 md:gap-x-4 w-full">
<ShimmeringLoader className="h-4 w-1/3 col-span-4" delayIndex={i} />
<ShimmeringLoader className="h-8 w-full col-span-8" delayIndex={i} />
</div>
<Separator />
</Fragment>
))}
<ShimmeringLoader className="h-8 w-full" />
</div>
)}
{!isHighAvailability && isErrorPgbouncerConfig && (
<AlertError
error={pgbouncerConfigError}
subject="Failed to retrieve connection pooler configuration"
/>
)}
{!isHighAvailability && connectionPoolingUnavailable && (
<Admonition
type="default"
title="Unable to retrieve pooling configuration"
description="Please start a new project to enable this feature"
/>
)}
{(isHighAvailability ||
(isSuccessPgbouncerConfig && !connectionPoolingUnavailable)) && (
<>
<div className="flex flex-row gap-2 justify-between w-full">
<div className="flex flex-col text-sm">
<h5 className="text-foreground font-normal">Connection poolers</h5>
<p className="text-foreground-lighter">
{isHighAvailability
? 'One pooler runs for each Postgres pod in the cluster.'
: 'Configuration is shared across all connection poolers.'}
</p>
</div>
<div className="flex flex-row gap-1 items-center">
{isHighAvailability ? (
<Badge>High Availability</Badge>
) : (
<>
<Badge>Shared</Badge>
{!disablePoolModeSelection && <Badge>Dedicated</Badge>}
</>
)}
</div>
</div>
<Separator className="bg-border -mx-6 w-[calc(100%+3rem)] my-4" />
<Form {...form}>
<form
id={formId}
className="flex flex-col gap-y-4 w-full"
onSubmit={form.handleSubmit(onSubmit)}
>
<FormField
control={form.control}
name="default_pool_size"
render={({ field }) => (
<FormItemLayout
layout="flex-row-reverse"
label="Connection pool size"
description={
isHighAvailability ? (
<p>
Pool size is managed automatically for each Postgres pod and cannot
be changed.
</p>
) : (
<p>
The maximum number of connections made to the underlying Postgres
cluster, per user+db combination. Pool size has a default of{' '}
{defaultPoolSize} based on your compute size of {computeSize}.
</p>
)
}
className="[&>div]:md:w-1/2 [&>div]:xl:w-2/5 [&>div>div]:w-full"
>
<FormControl>
<InputGroup>
<FormInputGroupInput
{...field}
disabled={isHighAvailability}
type="number"
className="w-full"
value={isHighAvailability ? '' : (field.value ?? '')}
placeholder={
isHighAvailability
? 'Managed automatically'
: defaultPoolSize.toString()
}
onChange={(event) =>
field.onChange(
isNaN(event.target.valueAsNumber)
? null
: event.target.valueAsNumber
)
}
/>
{!isHighAvailability && (
<InputGroupAddon align="inline-end">
<InputGroupText>connections</InputGroupText>
</InputGroupAddon>
)}
</InputGroup>
</FormControl>
{!isHighAvailability &&
!!maxConnData &&
(default_pool_size ?? 15) > maxConnData.maxConnections * 0.8 && (
<Alert variant="warning" className="mt-2">
<AlertTitle className="text-foreground">
Pool size is greater than 80% of the max connections (
{maxConnData.maxConnections}) on your database
</AlertTitle>
<AlertDescription>
This may result in instability and unreliability with your
database connections.
</AlertDescription>
</Alert>
)}
</FormItemLayout>
)}
/>
<Separator className="bg-border -mx-6 w-[calc(100%+3rem)]" />
<FormField
control={form.control}
disabled
name="max_client_conn"
render={({ field }) => (
<FormItemLayout
layout="flex-row-reverse"
label="Max client connections"
className="[&>div]:md:w-1/2 [&>div]:xl:w-2/5 [&>div>div]:w-full"
description={
isHighAvailability ? (
<p>
Each pooler can support up to{' '}
{HIGH_AVAILABILITY_MAX_CLIENT_CONNECTIONS.toLocaleString()} active
or passive client connections. This value is managed automatically
and cannot be changed.
</p>
) : (
<p>
The maximum number of concurrent client connections allowed. This
value is fixed at {defaultMaxClientConn} based on your compute size
of {computeSize} and cannot be changed.{' '}
<InlineLink
href={`${DOCS_URL}/guides/database/connection-management#configuring-supavisors-pool-size`}
>
Learn more
</InlineLink>
</p>
)
}
>
<FormControl>
<InputGroup>
<FormInputGroupInput
{...field}
type="number"
className="w-full"
value={
isHighAvailability
? HIGH_AVAILABILITY_MAX_CLIENT_CONNECTIONS
: (pgbouncerConfig?.max_client_conn ?? '')
}
placeholder={
isHighAvailability
? HIGH_AVAILABILITY_MAX_CLIENT_CONNECTIONS.toString()
: defaultMaxClientConn.toString()
}
onChange={(event) =>
field.onChange(
isNaN(event.target.valueAsNumber)
? null
: event.target.valueAsNumber
)
}
/>
<InputGroupAddon align="inline-end">
<InputGroupText>clients</InputGroupText>
</InputGroupAddon>
</InputGroup>
</FormControl>
</FormItemLayout>
)}
/>
</form>
</Form>
</>
)}
</Panel.Content>
</Panel>
</PageSectionContent>
</PageSection>
)
}