mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +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>
272 lines
9.2 KiB
TypeScript
272 lines
9.2 KiB
TypeScript
import {
|
|
FeatureFlagContext,
|
|
FeatureFlagContextType,
|
|
IS_PLATFORM,
|
|
useFeatureFlags,
|
|
useFlag,
|
|
} from 'common'
|
|
import { fullImageUrl } from 'common/marketplace-client'
|
|
import { BoxesIcon } from 'lucide-react'
|
|
import { lazy, useContext, useMemo } from 'react'
|
|
import { cn } from 'ui'
|
|
|
|
import { INTEGRATIONS, type IntegrationDefinition } from './Integrations.constants'
|
|
import {
|
|
useMarketplaceIntegrationsQuery,
|
|
type MarketplaceIntegration,
|
|
} from '@/data/marketplace/integrations-query'
|
|
import { useCLIReleaseVersionQuery } from '@/data/misc/cli-release-version-query'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { useIsWarehouseEnabled } from '@/hooks/misc/useIsWarehouseEnabled'
|
|
|
|
const MarketplaceIntegrationSettingsTab = lazy(() =>
|
|
import('@/components/interfaces/Integrations/Integration/MarketplaceIntegrationSettingsTab').then(
|
|
(mod) => ({ default: mod.MarketplaceIntegrationSettingsTab })
|
|
)
|
|
)
|
|
|
|
const renderMarketplaceLogo = (listingLogo?: string | null) => {
|
|
const MarketplaceLogo = ({ className, ...props }: { className?: string } = {}) => (
|
|
<div className="relative w-full h-full">
|
|
{listingLogo ? (
|
|
<img
|
|
src={fullImageUrl(listingLogo)}
|
|
alt=""
|
|
className={cn('w-full h-full p-2', className)}
|
|
{...props}
|
|
/>
|
|
) : (
|
|
<BoxesIcon className={cn('inset-0 p-2 text-black w-full h-full', className)} {...props} />
|
|
)}
|
|
</div>
|
|
)
|
|
return MarketplaceLogo
|
|
}
|
|
|
|
function isForeignDataWrapper(integration: MarketplaceIntegration) {
|
|
return integration.categories.some((c) => c?.slug === 'foreign-data-wrapper')
|
|
}
|
|
|
|
/**
|
|
* Use per-listing feature flags with a templated naming convention in order to independently
|
|
* enable/disable previews for users where the global `previewMarketplaceListingsEnabled` flag is not set.
|
|
*/
|
|
const isPreviewEnabled = (featureFlags: FeatureFlagContextType, listingSlug: string) => {
|
|
const flagName = `${listingSlug}DashboardIntegrationEnabled`
|
|
return (featureFlags.configcat[flagName] ?? false) as boolean
|
|
}
|
|
|
|
const useMarketplaceListings = () => {
|
|
const { hasLoaded } = useContext(FeatureFlagContext)
|
|
const { data: marketplaceData, error } = useMarketplaceIntegrationsQuery()
|
|
const isPending = IS_PLATFORM && (!hasLoaded || (!marketplaceData && !error))
|
|
const isSuccess = !IS_PLATFORM || (hasLoaded && !!marketplaceData && !error)
|
|
const isError = IS_PLATFORM && !!error
|
|
|
|
// This flag can globally enable preview listings for all partners for a given user (i.e. for Supabase users)
|
|
const previewAllListingsEnabled = useFlag<boolean>('previewMarketplaceListingsEnabled')
|
|
|
|
const featureFlags = useFeatureFlags()
|
|
|
|
const enabledListings = useMemo(
|
|
() =>
|
|
(marketplaceData ?? []).filter(
|
|
(integration) =>
|
|
integration.review_status === 'approved' ||
|
|
(integration.review_status === 'preview' &&
|
|
(previewAllListingsEnabled || isPreviewEnabled(featureFlags, integration.slug)))
|
|
),
|
|
[marketplaceData, previewAllListingsEnabled, featureFlags]
|
|
)
|
|
|
|
return { isPending, isSuccess, isError, data: enabledListings, error }
|
|
}
|
|
|
|
/**
|
|
* [Joshen] Returns a combination of
|
|
* - Marketplace integrations retrieved remotely (Only if feature flag enabled)
|
|
* - Existing integrations that are defined within studio
|
|
*/
|
|
export const useAvailableIntegrations = () => {
|
|
const { integrationsWrappers } = useIsFeatureEnabled(['integrations:wrappers'])
|
|
const isWarehouseAvailable = useIsWarehouseEnabled()
|
|
|
|
const { data: cliData } = useCLIReleaseVersionQuery()
|
|
const isCLI = !!cliData?.current
|
|
|
|
const {
|
|
isPending,
|
|
isSuccess,
|
|
isError,
|
|
data: marketplaceListings,
|
|
error,
|
|
} = useMarketplaceListings()
|
|
|
|
// [Joshen] Format marketplace integrations into existing ones for now
|
|
// Likely that we might need to change, but can look into separately
|
|
// Wrappers from marketplace are excluded here. They are merged into the
|
|
// hardcoded studio wrappers below as content overrides.
|
|
const marketplaceIntegrations: IntegrationDefinition[] = useMemo(
|
|
() =>
|
|
marketplaceListings
|
|
.filter((integration) => !isForeignDataWrapper(integration))
|
|
.map((integration) => {
|
|
const {
|
|
id: listingId,
|
|
slug,
|
|
categories,
|
|
featured,
|
|
title,
|
|
description,
|
|
documentation_url: docsUrl,
|
|
website_url: siteUrl,
|
|
installation_url: installUrl,
|
|
installation_url_type: installUrlType,
|
|
installation_identification_method: installMethod,
|
|
secret_key_prefix: secretKeyPrefix,
|
|
edge_function_secret_name: edgeFunctionSecretName,
|
|
images,
|
|
content,
|
|
built_by: authorName,
|
|
listing_logo: listingLogo,
|
|
oauth_app_id: oauthAppId,
|
|
} = integration
|
|
|
|
const status = undefined
|
|
const author = { name: authorName ?? '', websiteUrl: '' }
|
|
|
|
return {
|
|
id: slug ?? '',
|
|
name: title ?? '',
|
|
status,
|
|
featured: !!featured,
|
|
type: 'oauth' as const, // Currently marketplace only supports oauth apps
|
|
source: 'Partner' as const,
|
|
categories: categories.map((x) => x.slug),
|
|
content,
|
|
files: images?.map((image, i) => ({
|
|
src: fullImageUrl(image),
|
|
alt: `${title} image ${i + 1}`,
|
|
})),
|
|
description,
|
|
docsUrl,
|
|
siteUrl,
|
|
installUrl,
|
|
installUrlType: installUrlType ?? undefined,
|
|
installIdentificationMethod: installMethod ?? undefined,
|
|
secretKeyPrefix: secretKeyPrefix ?? undefined,
|
|
edgeFunctionSecretName: edgeFunctionSecretName ?? undefined,
|
|
oauthAppId: oauthAppId ?? undefined,
|
|
listingId: listingId ?? undefined,
|
|
author,
|
|
requiredExtensions: [],
|
|
icon: renderMarketplaceLogo(listingLogo),
|
|
navigation: [
|
|
{
|
|
route: 'overview',
|
|
label: 'Overview',
|
|
},
|
|
{
|
|
route: 'settings',
|
|
label: 'Settings',
|
|
layout: 'constrained',
|
|
},
|
|
],
|
|
navigate: ({ pageId = 'overview' }) => {
|
|
switch (pageId) {
|
|
case 'settings':
|
|
return MarketplaceIntegrationSettingsTab
|
|
}
|
|
return null
|
|
},
|
|
}
|
|
}),
|
|
[marketplaceListings]
|
|
)
|
|
|
|
// Marketplace wrapper listings keyed by their studio-equivalent id
|
|
// (marketplace uses dash-separated slugs, studio uses underscore-separated ids).
|
|
const marketplaceWrappers = useMemo(() => {
|
|
const map: Record<string, MarketplaceIntegration> = {}
|
|
marketplaceListings.forEach((integration) => {
|
|
if (!isForeignDataWrapper(integration)) return
|
|
map[integration.slug.replaceAll('-', '_')] = integration
|
|
})
|
|
return map
|
|
}, [marketplaceListings])
|
|
|
|
// [Joshen] Existing integrations that are defined within studio
|
|
// Available integrations are all integrations that can be installed. If an integration can't be installed (needed
|
|
// extensions are not available on this DB image), the UI will provide a tooltip explaining why.
|
|
const allIntegrations = useMemo(() => {
|
|
return INTEGRATIONS.filter((integration) => {
|
|
if (!integrationsWrappers && integration.type === 'wrapper') {
|
|
return false
|
|
}
|
|
|
|
if (integration.id === 'stripe_sync_engine' && isCLI) {
|
|
return false
|
|
}
|
|
|
|
// Warehouse is gated to an allow-list of orgs, and the API rejects every
|
|
// `/platform/warehouse/{ref}/*` call for the rest, so hide it entirely instead of showing an
|
|
// integration whose every request would fail.
|
|
if (integration.id === 'warehouse' && !isWarehouseAvailable) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}).map((integration) => {
|
|
const isWrapper = integration.type === 'wrapper'
|
|
if (!isWrapper) return integration
|
|
|
|
const marketplaceWrapper = marketplaceWrappers[integration.id]
|
|
if (!marketplaceWrapper) return integration
|
|
|
|
const {
|
|
title,
|
|
description,
|
|
content,
|
|
documentation_url: docsUrl,
|
|
website_url: siteUrl,
|
|
images,
|
|
built_by: authorName,
|
|
listing_logo: listingLogo,
|
|
} = marketplaceWrapper
|
|
|
|
const overrides = {
|
|
name: title,
|
|
description,
|
|
content,
|
|
docsUrl,
|
|
siteUrl,
|
|
author: authorName ? { name: authorName, websiteUrl: '' } : undefined,
|
|
files: images?.map((image, i) => ({
|
|
src: fullImageUrl(image),
|
|
alt: `${title} screenshot ${i + 1}`,
|
|
})),
|
|
icon: listingLogo ? renderMarketplaceLogo(listingLogo) : undefined,
|
|
}
|
|
|
|
return {
|
|
...integration,
|
|
...Object.fromEntries(Object.entries(overrides).filter(([, v]) => v != null)),
|
|
}
|
|
})
|
|
}, [integrationsWrappers, isCLI, isWarehouseAvailable, marketplaceWrappers])
|
|
|
|
const dataWithMarketplace = useMemo(() => {
|
|
return [...marketplaceIntegrations, ...allIntegrations].sort((a, b) =>
|
|
a.name.localeCompare(b.name)
|
|
)
|
|
}, [marketplaceIntegrations, allIntegrations])
|
|
|
|
return {
|
|
data: dataWithMarketplace,
|
|
error,
|
|
isPending,
|
|
isSuccess,
|
|
isError,
|
|
}
|
|
}
|