mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 19:05:06 +03:00
App-level fixes that reproduce on BOTH the Next and TanStack builds — split out of #47657 (which stays TanStack-only) for reviewability. All were found by a full-site click-through of the dashboard. ## Invalid HTML nesting (React 19 "will cause a hydration error" console errors) - **FormLayout description rendered in a `<p>`** (`packages/ui-patterns`): consumers pass arbitrary JSX (the RowEditor's `created_at` timezone note passes a `<div>` with `<p>`s) → `<p>`-in-`<p>` / `<div>`-in-`<p>`. Container is now a `<div>` with identical classes (Tailwind preflight makes them render the same). - **Switch toggles nested inside Tooltip trigger buttons** (button-in-button) in ColumnEditor ("Allow Nullable" + "Is Unique"), ExtensionRow, and PublicationsTableItem → repo-standard `TooltipTrigger asChild` + `<div>` wrapper. - **Saved log queries rendered a `<div>` directly inside `<tbody>`** (`/logs/explorer/saved`) → rows are now proper `<tr><td colSpan>` wrappers; the component itself is untouched (it's valid in its sidebar usage). - **Nested anchors in observability metric cards**: a card-level `<Link>` wrapped MetricCard's "More information" `<Link>` (identical URLs) → the chevron affordance renders as a `<span>` when no `href` is passed; clicks bubble to the card link, tooltips preserved. Design-system standalone usage unaffected. - **`objectFit="cover"` passed to modern `next/image`** on the featured integration card (unknown-prop warning) — the className already had `object-cover`; prop dropped. ## Ghost dead-snippet after deletion Deleting the active SQL snippet left its id in `useDashboardHistory` (`history.sql`), so the "SQL Editor" nav item navigated to `/sql/<deleted-id>` — content fetch 404s, no editor pane renders, and a phantom tab reappears. Fixed both ends: delete flows now purge dashboard history (and the tabs store clears a stale `previewTabId`), and `/sql/[id]` treats a snippet 404 as "clean up + `router.replace` to `/sql/new` + toast" instead of rendering the dead state. Unit tests for the store/history cleanup. ## `pg-meta` migrations query 400s on every project load `ActivityStats` on project home runs the migrations list query, whose SQL was a bare `select * from supabase_migrations.schema_migrations` — that table only exists once a migration has run, so every other project logged a failed `?key=migrations` request on every load (visible in production consoles too). The SQL is now guarded with `to_regclass` + `query_to_xml` (same pattern as the advisor lints' `storage.buckets` guard), returning zero rows instead of erroring; legacy version-only tables still work. Tested against real dockerized Postgres (absent table, populated ordering, special chars, legacy schema) + MSW hook tests. Found and verified via /test-supabase-local (browser click-through + console audit on both builds). ## To test Console must stay free of React DOM-nesting errors ("cannot be a descendant of" / "cannot contain a nested") on each surface: 1. Table editor → Insert row panel (`created_at` field renders its timezone note) and Edit column panel ("Allow Nullable"/"Is Unique" tooltips still hover). 2. `/database/extensions` and `/database/publications` → toggle switches render, tooltips hover. 3. `/logs/explorer/saved` (with ≥1 saved query) → rows render full-width inside the table, hover shows Actions. 4. `/observability` → no nested-anchor error on load; card body click and the chevron both navigate; label help-icons still show tooltips. 5. `/integrations` → no `objectFit` unknown-prop warning; featured card images still cover. 6. **Ghost snippet**: open a SQL snippet → delete it via the sidebar → click the "SQL Editor" nav item → lands on `/sql/new` (no phantom tab, no 404 content fetch). Direct-load `/sql/<random-uuid>` → toast + redirect to `/sql/new`. 7. **Migrations 400**: load project home with a project that has never run a migration → the `pg-meta/<ref>/query?key=migrations` request returns **200** with `[]` (previously a 400 on every load). Database → Migrations still lists real migrations when they exist. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit * **Bug Fixes** * Deleted SQL snippets are fully removed from dashboard history and stale editor/tab state; users are redirected with a toast. * Closing preview tabs no longer leaves stale references. * Improved toggle/tooltip/dialog interactions to avoid broken UI, including metric headers showing tooltips even without direct links. * Migrations display safely when migration tables/relations are missing. * **UI Improvements** * Refreshed layout for saved queries, form descriptions, and integration imagery. * **Tests** * Added coverage for snippet history cleanup, tab removal, migrations SQL behavior, and query edge cases. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- ### Review feedback: `query_to_xml` breaks on Multigres (Ivan) The defensive migrations query (added here to stop the `?key=migrations` 400 when the table doesn't exist yet) originally guarded with `query_to_xml`, which is forbidden through Multigres's pooler (MUL-736 / PSQL-1318). Rewritten without `query_to_xml`/`xmltable` using the splinter#170 pattern: a PL/pgSQL `do` block guarded by `to_regclass` (PL/pgSQL defers planning, so a missing table never errors) stashes the rows into a transaction-local GUC via `set_config`, and a trailing `select` reads them back with `jsonb_array_elements`. Verified that postgres-meta sends the whole SQL as one simple-query string → single implicit transaction → the local GUC survives to the `select` and doesn't leak into the pooled connection. 6/6 dockerized-Postgres tests (absent table → `[]`, populated/ordered/special-chars, legacy version-only table, full pg-meta-shaped multi-statement string, GUC non-leakage). Note (out of scope, pre-existing): `packages/pg-meta/src/sql/studio/advisor/lints.ts` still uses `query_to_xml` — a separate pre-existing Multigres risk that should get its own splinter-pattern sync. --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
216 lines
7.8 KiB
TypeScript
216 lines
7.8 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { AlertTriangle, Book, Github, Loader2 } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { useState } from 'react'
|
|
import { extensions } from 'shared-data'
|
|
import { toast } from 'sonner'
|
|
import { Button, Switch, TableCell, TableRow, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
import { Admonition } from 'ui-patterns/admonition'
|
|
import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal'
|
|
|
|
import { EnableExtensionModal } from './EnableExtensionModal'
|
|
import { EXTENSION_DISABLE_WARNINGS } from './Extensions.constants'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { useDatabaseExtensionDisableMutation } from '@/data/database-extensions/database-extension-disable-mutation'
|
|
import { DatabaseExtension } from '@/data/database-extensions/database-extensions-query'
|
|
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
|
|
import { useIsOrioleDb, useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { DOCS_URL } from '@/lib/constants'
|
|
|
|
interface ExtensionRowProps {
|
|
extension: DatabaseExtension
|
|
}
|
|
|
|
export const ExtensionRow = ({ extension }: ExtensionRowProps) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const isOn = extension.installed_version !== null
|
|
const isOrioleDb = useIsOrioleDb()
|
|
|
|
const [isDisableModalOpen, setIsDisableModalOpen] = useState(false)
|
|
const [showConfirmEnableModal, setShowConfirmEnableModal] = useState(false)
|
|
|
|
const { can: canUpdateExtensions } = useAsyncCheckPermissions(
|
|
PermissionAction.TENANT_SQL_ADMIN_WRITE,
|
|
'extensions'
|
|
)
|
|
const orioleDbCheck = isOrioleDb && extension.name === 'orioledb'
|
|
const disabled = !canUpdateExtensions || orioleDbCheck
|
|
|
|
const extensionMeta = extensions.find((item) => item.name === extension.name)
|
|
const docsUrl = extensionMeta?.link.startsWith('/guides')
|
|
? `${DOCS_URL}${extensionMeta?.link}`
|
|
: (extensionMeta?.link ?? undefined)
|
|
|
|
const { mutate: disableExtension, isPending: isDisabling } = useDatabaseExtensionDisableMutation({
|
|
onSuccess: () => {
|
|
toast.success(`${extension.name} is off.`)
|
|
setIsDisableModalOpen(false)
|
|
},
|
|
})
|
|
|
|
const onConfirmDisable = () => {
|
|
if (project === undefined) return console.error('Project is required')
|
|
|
|
disableExtension({
|
|
projectRef: project.ref,
|
|
connectionString: project.connectionString,
|
|
id: extension.name,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<TableRow>
|
|
<TableCell>
|
|
<div className="flex items-center gap-x-2">
|
|
<span title={extension.name} className="truncate inline-block max-w-48">
|
|
{extension.name}
|
|
</span>
|
|
{extensionMeta?.deprecated && extensionMeta?.deprecated.length > 0 && (
|
|
<ButtonTooltip
|
|
variant="warning"
|
|
icon={<AlertTriangle />}
|
|
className="rounded-full"
|
|
tooltip={{
|
|
content: {
|
|
text: `The extension is deprecated and will be removed in ${extensionMeta.deprecated.join(', ')}.`,
|
|
},
|
|
}}
|
|
>
|
|
Deprecated
|
|
</ButtonTooltip>
|
|
)}
|
|
</div>
|
|
</TableCell>
|
|
|
|
<TableCell className="w-28 font-mono tracking-tighter">
|
|
{extension?.installed_version ?? extension.default_version}
|
|
</TableCell>
|
|
|
|
<TableCell className="truncate">{isOn ? extension.schema : '-'}</TableCell>
|
|
|
|
<TableCell className="text-foreground-light">
|
|
<p className="block" title={extension.comment ?? undefined}>
|
|
{extension.comment}
|
|
</p>
|
|
</TableCell>
|
|
|
|
<TableCell>
|
|
{extensionMeta?.product ? (
|
|
<div className="flex flex-col gap-1">
|
|
{extensionMeta.product_url ? (
|
|
<Link
|
|
href={extensionMeta.product_url.replace('{ref}', project?.ref ?? '')}
|
|
className="transition hover:text-foreground"
|
|
>
|
|
{extensionMeta.product}
|
|
</Link>
|
|
) : (
|
|
<span>{extensionMeta.product}</span>
|
|
)}
|
|
{!isOn && (
|
|
<span className="text-foreground-lighter text-xs">
|
|
Install extension to use {extensionMeta.product}
|
|
</span>
|
|
)}
|
|
</div>
|
|
) : (
|
|
<span className="text-foreground-lighter">-</span>
|
|
)}
|
|
</TableCell>
|
|
|
|
<TableCell>
|
|
<div className="flex gap-2 items-center">
|
|
{extensionMeta?.github_url && (
|
|
<Button asChild variant="default" icon={<Github />} className="rounded-full">
|
|
<a
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
href={extensionMeta.github_url}
|
|
className="font-mono tracking-tighter"
|
|
>
|
|
{extensionMeta.github_url.split('/').slice(-2).join('/')}
|
|
</a>
|
|
</Button>
|
|
)}
|
|
{docsUrl !== undefined && (
|
|
<Button asChild variant="default" icon={<Book />} className="rounded-full">
|
|
<a
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="font-mono tracking-tighter"
|
|
href={docsUrl}
|
|
>
|
|
Docs
|
|
</a>
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</TableCell>
|
|
|
|
{/*
|
|
[Joshen] The div child here and all these classes is to properly add a left border
|
|
to make the sticky column more distinct
|
|
*/}
|
|
<TableCell className="w-20 sticky bg-surface-100 right-0 relative">
|
|
<div className="absolute top-0 right-0 left-0 bottom-0 flex items-center justify-center border-l">
|
|
{isDisabling ? (
|
|
<Loader2 className="animate-spin" size={16} />
|
|
) : (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<div>
|
|
<Switch
|
|
aria-label="Toggle extension"
|
|
disabled={disabled}
|
|
checked={isOn}
|
|
onCheckedChange={() =>
|
|
isOn ? setIsDisableModalOpen(true) : setShowConfirmEnableModal(true)
|
|
}
|
|
/>
|
|
</div>
|
|
</TooltipTrigger>
|
|
{disabled && (
|
|
<TooltipContent side="bottom">
|
|
{!canUpdateExtensions
|
|
? 'You need additional permissions to toggle extensions'
|
|
: orioleDbCheck
|
|
? 'Project is using OrioleDB and cannot be disabled'
|
|
: null}
|
|
</TooltipContent>
|
|
)}
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
</TableCell>
|
|
</TableRow>
|
|
|
|
<EnableExtensionModal
|
|
visible={showConfirmEnableModal}
|
|
extension={extension}
|
|
onCancel={() => setShowConfirmEnableModal(false)}
|
|
/>
|
|
|
|
<ConfirmationModal
|
|
visible={isDisableModalOpen}
|
|
title="Confirm to disable extension"
|
|
confirmLabel="Disable"
|
|
variant="destructive"
|
|
confirmLabelLoading="Disabling"
|
|
loading={isDisabling}
|
|
onCancel={() => setIsDisableModalOpen(false)}
|
|
onConfirm={() => onConfirmDisable()}
|
|
>
|
|
<div className="flex flex-col gap-y-3">
|
|
<p className="text-sm text-foreground-light">
|
|
Are you sure you want to turn OFF the "{extension.name}" extension?
|
|
</p>
|
|
{EXTENSION_DISABLE_WARNINGS[extension.name] && (
|
|
<Admonition type="warning">{EXTENSION_DISABLE_WARNINGS[extension.name]}</Admonition>
|
|
)}
|
|
</div>
|
|
</ConfirmationModal>
|
|
</>
|
|
)
|
|
}
|