mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem
Now that Studio runs on TanStack Start, `apps/studio` still routes 13
`next/dynamic` imports through a local compatibility shim
(`apps/studio/compat/next/dynamic.tsx` aliased in
`apps/studio/vite.config.ts`). Keeping the shim adds unnecessary
indirection during the Next.js teardown (FE-5113).
## Solution
Replaces every `next/dynamic` import in `apps/studio` with `React.lazy`
+ `Suspense` (or static imports where already inside a lazy chunk), then
deletes `compat/next/dynamic.tsx` and its Vite alias.
None of the previously `ssr: false` call sites need `ClientOnly`: Studio
runs TanStack Start with `spa: { enabled: true }` and only prerenders
the signed-out auth routes (`/sign-in`, `/sign-up`, `/sign-in-sso`,
`/forgot-password`), `__root.tsx` gates `<Outlet />` behind
`canRenderPage`, and `StudioCommandMenu` is already gated by
`useCommandMenuInitiated()` (which starts `false` per render).
**Removed:**
- `apps/studio/compat/next/dynamic.tsx` and the `'next/dynamic'` entry
in `nextShims` in `apps/studio/vite.config.ts`
**Changed:**
- Migrated all `next/dynamic` call sites to `React.lazy` + `Suspense`:
- `StudioCommandMenu`, `ContextSearchResults`,
`Marketplace/OverviewTab`, `QueryDetail` (`SqlMonacoBlock`),
`SQLEditorEditorPanel` (`MonacoEditor`, `DiffEditor`),
`SupportAssistantSuccessCard`, `LayoutSidebarProvider`,
`MessageMarkdown` (`Streamdown`), and
`SupportAssistantSuccessCardContent` (`Streamdown`)
- `ConnectStepsSection`: hoisted the lazy component cache out of
`useMemo` to module scope (also clears its
`react/no-unstable-nested-components` warning)
- `Integrations.constants.tsx` and `useAvailableIntegrations.tsx`:
hoisted all lazy integration tab/page definitions (including
`GraphiQLTab`) to module scope so `navigate()` returns stable component
references, added `Suspense` boundaries with `<Loading />` at both
render points (`MarketplaceDetail` and the integration child route), and
keyed integration tab/creation sheet instances (`integration.id` in
`MarketplaceDetail` and `wrapperMeta.name` in `WrappersTab`) so state
cannot leak when switching between wrappers or OAuth integrations;
preserves `umdAmdShortCircuit`, `ssrStubGraphiql`, and
`graphiqlViteWorkers` in `vite.config.ts`
- Replaced `dynamic()` calls for `AiIconAnimation`, `Badge`, and 4
`icons` in `CreateCommands.tsx` with static imports (already inside the
lazy `CommandMenu` chunk)
- Removed the stale `next/dynamic` mention from the
`lib/chunk-load-error.ts` doc comment (`React.lazy` chunk failures
continue bubbling to the root `ErrorBoundary` reload handler)
**Added:**
- Reference-stability tests for `INTEGRATIONS.navigate` in
`Integrations.constants.test.ts` (running in Vitest's Node environment)
## Review instructions
1. Open the SQL Editor and Query Performance query detail panel, and
confirm the Monaco editor and diff view load cleanly.
2. Open the GraphQL integration's GraphiQL tab, and confirm the loading
skeleton displays while the chunk loads and GraphiQL mounts with working
autocomplete/workers.
3. Open a Wrapper integration's Wrappers tab, open the create sheet,
then navigate via history to a different wrapper's create sheet and
confirm the form resets to the new wrapper's defaults.
4. Open the Command Menu (`Cmd+K`), navigate to context search (for
example, Search Database Tables) and Create commands, and confirm icons,
badges, and search results load without flicker.
5. Open the Connect sheet and switch between frameworks/steps,
confirming step content loads with the skeleton fallback.
6. Toggle sidebars (AI Assistant, Inline SQL Editor, Advisor, Help) and
verify markdown streaming in AI Assistant.
7. Confirm CI passes `pnpm --filter studio run build` (including
prerendering and chunk-cycle checks), typecheck, lint ratchet, and
Studio tests.
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
471 lines
14 KiB
TypeScript
471 lines
14 KiB
TypeScript
'use client'
|
|
|
|
import { IS_PLATFORM } from 'common'
|
|
import { AnalyticsBucket, EdgeFunctions, FilesBucket, VectorBucket } from 'icons'
|
|
import {
|
|
Clock5Icon,
|
|
Code2Icon,
|
|
KeyRoundIcon,
|
|
LayersIcon,
|
|
ListChecksIcon,
|
|
LockIcon,
|
|
LockKeyholeIcon,
|
|
MailIcon,
|
|
MessageCircleIcon,
|
|
PlusIcon,
|
|
RowsIcon,
|
|
ShieldPlusIcon,
|
|
Table2Icon,
|
|
TelescopeIcon,
|
|
UserCogIcon,
|
|
UserPlusIcon,
|
|
VaultIcon,
|
|
WebhookIcon,
|
|
ZapIcon,
|
|
} from 'lucide-react'
|
|
import { useMemo } from 'react'
|
|
import { AiIconAnimation, Badge } from 'ui'
|
|
import type { CommandOptions, ICommand } from 'ui-patterns/CommandMenu'
|
|
import {
|
|
PageType,
|
|
useRegisterCommands,
|
|
useRegisterPage,
|
|
useSetCommandMenuOpen,
|
|
} from 'ui-patterns/CommandMenu'
|
|
|
|
import { COMMAND_MENU_SECTIONS } from './CommandMenu.utils'
|
|
import {
|
|
getIntegrationCommandName,
|
|
getIntegrationRoute,
|
|
useCreateCommandsConfig,
|
|
} from './CreateCommands.utils'
|
|
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
|
|
|
|
const CREATE_STUDIO_ENTITY = 'Create Studio Entity'
|
|
|
|
export function useCreateCommands(options?: CommandOptions) {
|
|
const setIsOpen = useSetCommandMenuOpen()
|
|
const {
|
|
ref,
|
|
setPage,
|
|
openSidebar,
|
|
snap,
|
|
authEnabled,
|
|
edgeFunctionsEnabled,
|
|
storageEnabled,
|
|
sendSmsHook,
|
|
sendEmailHook,
|
|
customAccessTokenHook,
|
|
mfaVerificationHook,
|
|
mfaVerificationHookEnabled,
|
|
passwordVerificationHook,
|
|
passwordVerificationHookEnabled,
|
|
beforeUserCreatedHook,
|
|
isVectorBucketsEnabled,
|
|
isAnalyticsBucketsEnabled,
|
|
installedIntegrationIds,
|
|
allIntegrations,
|
|
reportsEnabled,
|
|
} = useCreateCommandsConfig()
|
|
|
|
const databaseCommands = useMemo(
|
|
() =>
|
|
[
|
|
{
|
|
id: 'create-db-table',
|
|
name: 'Create Table',
|
|
route: `/project/${ref}/editor?create=table`,
|
|
icon: () => <Table2Icon />,
|
|
},
|
|
{
|
|
id: 'create-db-index',
|
|
name: 'Create Index',
|
|
route: `/project/${ref}/database/indexes?new=true`,
|
|
icon: () => <RowsIcon />,
|
|
},
|
|
{
|
|
id: 'create-db-function',
|
|
name: 'Create Database Function',
|
|
route: `/project/${ref}/database/functions?new=true`,
|
|
icon: () => <Code2Icon />,
|
|
},
|
|
{
|
|
id: 'create-db-enum',
|
|
name: 'Create Enumerated Type',
|
|
route: `/project/${ref}/database/types?new=true`,
|
|
icon: () => <ListChecksIcon />,
|
|
},
|
|
{
|
|
id: 'create-db-trigger',
|
|
name: 'Create Database Trigger',
|
|
route: `/project/${ref}/database/triggers?new=true`,
|
|
icon: () => <ZapIcon />,
|
|
},
|
|
{
|
|
id: 'create-db-role',
|
|
name: 'Create Database Role',
|
|
route: `/project/${ref}/database/roles?new=true`,
|
|
icon: () => <UserCogIcon />,
|
|
},
|
|
].filter(Boolean) as ICommand[],
|
|
[ref]
|
|
)
|
|
|
|
const authCommands = useMemo(
|
|
() =>
|
|
authEnabled
|
|
? ([
|
|
{
|
|
id: 'create-auth-user',
|
|
name: 'Create Auth User',
|
|
route: `/project/${ref}/auth/users?new=true`,
|
|
icon: () => <UserPlusIcon />,
|
|
},
|
|
{
|
|
id: 'create-rls-policy',
|
|
name: 'Create RLS Policy',
|
|
route: `/project/${ref}/database/policies?new=true`,
|
|
icon: () => <ShieldPlusIcon />,
|
|
},
|
|
...(IS_PLATFORM
|
|
? [
|
|
{
|
|
id: 'create-auth-hook-sms',
|
|
name: 'Create Auth Hook (SMS)',
|
|
route: `/project/${ref}/auth/hooks?hook=${sendSmsHook?.id}`,
|
|
icon: () => <MessageCircleIcon />,
|
|
},
|
|
{
|
|
id: 'create-auth-hook-email',
|
|
name: 'Create Auth Hook (Email)',
|
|
route: `/project/${ref}/auth/hooks?hook=${sendEmailHook?.id}`,
|
|
icon: () => <MailIcon />,
|
|
},
|
|
{
|
|
id: 'create-auth-hook-custom-access-token',
|
|
name: 'Create Auth Hook (Custom Access Token)',
|
|
route: `/project/${ref}/auth/hooks?hook=${customAccessTokenHook?.id}`,
|
|
icon: () => <KeyRoundIcon />,
|
|
},
|
|
{
|
|
id: 'create-auth-hook-mfa-verification',
|
|
name: 'Create Auth Hook (MFA Verification Attempt)',
|
|
route: `/project/${ref}/auth/hooks?hook=${mfaVerificationHook?.id}`,
|
|
icon: () => <ShieldPlusIcon />,
|
|
badge: () => (mfaVerificationHookEnabled ? <Badge>Team</Badge> : null),
|
|
className: mfaVerificationHookEnabled
|
|
? 'opacity-50 cursor-not-allowed pointer-events-none'
|
|
: '',
|
|
},
|
|
{
|
|
id: 'create-auth-hook-password-verification',
|
|
name: 'Create Auth Hook (Password Verification Attempt)',
|
|
route: `/project/${ref}/auth/hooks?hook=${passwordVerificationHook?.id}`,
|
|
icon: () => <LockIcon />,
|
|
badge: () => (passwordVerificationHookEnabled ? <Badge>Team</Badge> : null),
|
|
className: passwordVerificationHookEnabled
|
|
? 'opacity-50 cursor-not-allowed pointer-events-none'
|
|
: '',
|
|
},
|
|
{
|
|
id: 'create-auth-hook-before-user-created',
|
|
name: 'Create Auth Hook (Before User Created)',
|
|
route: `/project/${ref}/auth/hooks?hook=${beforeUserCreatedHook?.id}`,
|
|
icon: () => <KeyRoundIcon />,
|
|
},
|
|
]
|
|
: []),
|
|
...(IS_PLATFORM
|
|
? [
|
|
{
|
|
id: 'create-oauth-app',
|
|
name: 'Create OAuth App',
|
|
route: `/project/${ref}/auth/oauth-apps?new=true`,
|
|
icon: () => <KeyRoundIcon />,
|
|
},
|
|
]
|
|
: []),
|
|
].filter(Boolean) as ICommand[])
|
|
: [],
|
|
[
|
|
ref,
|
|
authEnabled,
|
|
sendSmsHook,
|
|
sendEmailHook,
|
|
customAccessTokenHook,
|
|
mfaVerificationHook,
|
|
mfaVerificationHookEnabled,
|
|
passwordVerificationHook,
|
|
passwordVerificationHookEnabled,
|
|
beforeUserCreatedHook,
|
|
]
|
|
)
|
|
|
|
const edgeFunctionsCommands = useMemo(
|
|
() =>
|
|
edgeFunctionsEnabled
|
|
? ([
|
|
{
|
|
id: 'create-edge-function-editor',
|
|
name: 'Create Edge Function via Editor',
|
|
route: `/project/${ref}/functions/new`,
|
|
icon: () => <EdgeFunctions />,
|
|
},
|
|
{
|
|
id: 'create-edge-function-cli',
|
|
name: 'Create Edge Function via CLI',
|
|
route: `/project/${ref}/functions?create=cli`,
|
|
icon: () => <EdgeFunctions />,
|
|
},
|
|
{
|
|
id: 'create-edge-function-ai',
|
|
name: 'Create Edge Function via AI',
|
|
action: () => {
|
|
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
|
|
snap.newChat({
|
|
name: 'Create new edge function',
|
|
initialInput: `Create a new edge function that ...`,
|
|
suggestions: {
|
|
title:
|
|
'I can help you create a new edge function. Here are a few example prompts to get you started:',
|
|
prompts: [
|
|
{
|
|
label: 'Stripe Payments',
|
|
description:
|
|
'Create a new edge function that processes payments with Stripe',
|
|
},
|
|
{
|
|
label: 'Email with Resend',
|
|
description: 'Create a new edge function that sends emails with Resend',
|
|
},
|
|
{
|
|
label: 'PDF Generator',
|
|
description:
|
|
'Create a new edge function that generates PDFs from HTML templates',
|
|
},
|
|
],
|
|
},
|
|
})
|
|
setIsOpen(false)
|
|
},
|
|
icon: () => (
|
|
<AiIconAnimation
|
|
allowHoverEffect={false}
|
|
size={20}
|
|
className="text-foreground-light"
|
|
/>
|
|
),
|
|
},
|
|
{
|
|
id: 'create-edge-function-secret',
|
|
name: 'Create Edge Function Secret',
|
|
route: `/project/${ref}/functions/secrets`,
|
|
icon: () => <LockKeyholeIcon />,
|
|
},
|
|
].filter(Boolean) as ICommand[])
|
|
: [],
|
|
[ref, edgeFunctionsEnabled, openSidebar, snap, setIsOpen]
|
|
)
|
|
|
|
const storageCommands = useMemo(
|
|
() =>
|
|
storageEnabled
|
|
? ([
|
|
{
|
|
id: 'create-storage-bucket-files',
|
|
name: 'Create Storage Bucket (Files)',
|
|
route: `/project/${ref}/storage/files?new=true`,
|
|
icon: () => <FilesBucket />,
|
|
},
|
|
{
|
|
id: 'create-storage-bucket-analytics',
|
|
name: 'Create Storage Bucket (Analytics)',
|
|
route: `/project/${ref}/storage/analytics?new=true`,
|
|
icon: () => <AnalyticsBucket />,
|
|
badge: () => <Badge variant="success">New</Badge>,
|
|
className: !isAnalyticsBucketsEnabled
|
|
? 'opacity-50 cursor-not-allowed pointer-events-none'
|
|
: '',
|
|
enabled: isAnalyticsBucketsEnabled,
|
|
},
|
|
{
|
|
id: 'create-storage-bucket-vectors',
|
|
name: 'Create Storage Bucket (Vectors)',
|
|
route: `/project/${ref}/storage/vectors?new=true`,
|
|
icon: () => <VectorBucket />,
|
|
badge: () => <Badge variant="success">New</Badge>,
|
|
className: !isVectorBucketsEnabled
|
|
? 'opacity-50 cursor-not-allowed pointer-events-none'
|
|
: '',
|
|
enabled: isVectorBucketsEnabled,
|
|
},
|
|
].filter(Boolean) as ICommand[])
|
|
: [],
|
|
[ref, storageEnabled, isAnalyticsBucketsEnabled, isVectorBucketsEnabled]
|
|
)
|
|
|
|
const integrationsCommands = useMemo(() => {
|
|
// Sort integrations: Postgres modules (non-wrappers) first, then wrappers
|
|
const sortedIntegrations = [...allIntegrations].sort((a, b) => {
|
|
const aIsWrapper = a.type === 'wrapper' ? 1 : 0
|
|
const bIsWrapper = b.type === 'wrapper' ? 1 : 0
|
|
return aIsWrapper - bIsWrapper
|
|
})
|
|
|
|
return sortedIntegrations
|
|
.map((integration) => {
|
|
const route = getIntegrationRoute(integration, ref, installedIntegrationIds)
|
|
if (!route) return null
|
|
|
|
const isWrapper = integration.type === 'wrapper'
|
|
|
|
// For wrappers, use the integration icon with wrapper styling
|
|
// For Postgres modules, use plain icons
|
|
const getIcon = () => {
|
|
if (isWrapper) {
|
|
return (
|
|
<div className="w-6 h-6 relative bg-white border rounded-md flex items-center justify-center [&>img]:p-1! [&>svg]:p-1!">
|
|
{integration.icon()}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
// Use plain icons for Postgres modules
|
|
switch (integration.id) {
|
|
case 'vault':
|
|
return <VaultIcon />
|
|
case 'cron':
|
|
return <Clock5Icon />
|
|
case 'webhooks':
|
|
return <WebhookIcon />
|
|
case 'queues':
|
|
return <LayersIcon />
|
|
default:
|
|
// Fallback to integration icon for other Postgres modules
|
|
return integration.icon()
|
|
}
|
|
}
|
|
|
|
return {
|
|
id: `create-integration-${integration.id}`,
|
|
name: getIntegrationCommandName(integration),
|
|
route,
|
|
icon: getIcon,
|
|
}
|
|
})
|
|
.filter(Boolean) as ICommand[]
|
|
}, [ref, allIntegrations, installedIntegrationIds])
|
|
|
|
// Observability commands are only available on the platform, not for self-hosted/CLI
|
|
const observabilityCommands = useMemo(
|
|
() => [
|
|
...(IS_PLATFORM
|
|
? reportsEnabled
|
|
? ([
|
|
{
|
|
id: 'create-observability-report',
|
|
name: 'Create Custom Report',
|
|
route: `/project/${ref}/observability/api-overview?newReport=true`,
|
|
icon: () => <TelescopeIcon />,
|
|
},
|
|
].filter(Boolean) as ICommand[])
|
|
: []
|
|
: []),
|
|
],
|
|
[ref, reportsEnabled]
|
|
)
|
|
|
|
const sections = useMemo(
|
|
() => [
|
|
{
|
|
id: 'create-database',
|
|
name: 'Database',
|
|
commands: databaseCommands,
|
|
},
|
|
...(authCommands.length > 0
|
|
? [
|
|
{
|
|
id: 'create-auth',
|
|
name: 'Auth',
|
|
commands: authCommands,
|
|
},
|
|
]
|
|
: []),
|
|
...(edgeFunctionsCommands.length > 0
|
|
? [
|
|
{
|
|
id: 'create-edge-functions',
|
|
name: 'Edge Functions',
|
|
commands: edgeFunctionsCommands,
|
|
},
|
|
]
|
|
: []),
|
|
...(storageCommands.length > 0
|
|
? [
|
|
{
|
|
id: 'create-storage',
|
|
name: 'Storage',
|
|
commands: storageCommands,
|
|
},
|
|
]
|
|
: []),
|
|
...(observabilityCommands.length > 0
|
|
? [
|
|
{
|
|
id: 'create-observability',
|
|
name: 'Observability',
|
|
commands: observabilityCommands,
|
|
},
|
|
]
|
|
: []),
|
|
...(integrationsCommands.length > 0
|
|
? [
|
|
{
|
|
id: 'create-integrations',
|
|
name: 'Integrations',
|
|
commands: integrationsCommands,
|
|
},
|
|
]
|
|
: []),
|
|
],
|
|
[
|
|
databaseCommands,
|
|
authCommands,
|
|
edgeFunctionsCommands,
|
|
storageCommands,
|
|
integrationsCommands,
|
|
observabilityCommands,
|
|
]
|
|
)
|
|
|
|
useRegisterPage(
|
|
CREATE_STUDIO_ENTITY,
|
|
{
|
|
type: PageType.Commands,
|
|
sections,
|
|
},
|
|
{
|
|
deps: [sections],
|
|
enabled: true,
|
|
}
|
|
)
|
|
|
|
useRegisterCommands(
|
|
COMMAND_MENU_SECTIONS.ACTIONS,
|
|
[
|
|
{
|
|
id: 'create-studio-entity',
|
|
name: 'Create...',
|
|
action: () => setPage(CREATE_STUDIO_ENTITY),
|
|
icon: () => <PlusIcon />,
|
|
},
|
|
],
|
|
{
|
|
...options,
|
|
orderSection: (sections) => sections,
|
|
sectionMeta: { priority: 3 },
|
|
enabled: true,
|
|
}
|
|
)
|
|
}
|