mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
7.2 KiB
7.2 KiB
Supabase Studio
TanStack Start + React 19. Dev server: pnpm dev:studio → http://localhost:8082.
Skills — load before working
Load every skill matching the task; stack them when a task spans areas:
| Task | Skill |
|---|---|
Routes, layouts, redirects, server API handlers (routes/**) |
studio-routes |
Query/mutation hooks, query keys (data/**) |
studio-queries |
| UI: pages, links, tables, charts, dialogs, sheets, empty states, a11y | studio-ui-patterns |
| Form logic: react-hook-form fields, watch/formState, reset, number inputs | react-hook-form |
| Displaying API errors | studio-error-handling |
| Tests: deciding, writing, reviewing unit & MSW component tests | studio-testing |
Playwright E2E tests (e2e/studio/**) |
studio-e2e-tests |
| PostHog event tracking | telemetry-standards |
| SQL against user databases or analytics logs | safe-sql-execution |
Logs Explorer SQL, data/logs |
clickhouse-logs-queries |
| Keyboard shortcuts, search/filter inputs | studio-shortcuts |
| User-facing copy | copywriting |
Orientation
- Routing — TanStack Start file routes under
routes/**;routeTree.gen.tsis generated (never hand-edit). Use native TanStack APIs (nonext/*imports); loadstudio-routesfor route modules, redirects, androutes/api/**. - Data & state — Platform API calls go through
data/fetchers.ts(openapi-fetch+api-types) withhandleError; never rawfetch. State:valtio(state/),nuqs(URL),react-hook-form+zod(forms). - Platform & flags —
IS_PLATFORMgates platform-only behavior (withAuthis a no-op self-hosted). Gate platform/flag-only UI in the parent before mounting or fetching; disabled flagged UI early-returnsnull(verify both states). - Tests — Write tests only when they guard a plausible runtime regression static analysis cannot catch. Skipping tests for static copy, pure markup, constants, pass-through wrappers, and standard
data/**hooks/keys is expected (studio-testing). - Assistant & PATs — Read lib/ai/README.md before changing Assistant chat, tools, prompts, or access handling (and update it when moving entry points or changing the request/tool lifecycle). After editing
packages/shared-data/scoped-access-token-permissions.ts, runmake -C apps/docs/spec generate.partials.access-control. - Reuse first — Search
hooks/,lib/,packages/common, andpackages/ui-patternsbefore adding helpers. ReuseEMPTY_ARR/EMPTY_OBJ(lib/void),pluralize/formatCurrency(lib/helpers),getErrorMessage(lib/get-error-message),useLatest(hooks/misc/useLatest),useOnChange(common), andcn(ui).
Engineering principles
Older Studio code predates these conventions. Follow them in new or modified code rather than copying legacy neighbors:
- Boundary & contract honesty — Validate untrusted inputs at entry (URL params, JSON,
process.env, caughtunknown) with Zod or guards; inside, trust contracts and fix drift inpackages/api-types(satisfies) rather thanascasts or defensive shims. - Async & lifecycle completeness — Walk pending, in-flight, error, empty, and closed states: unsettled queries never read as
false/0, errors never collapse into empty states, slow actions lock in-flight, controlled inputs stay defined, and modals reset on close. - State &
useEffect— Keep state local, derive values instead of mirroring inuseState(Boolean(selectedId)), and avoid unnecessary React Context. UseuseEffectonly for external sync right beforereturn; fixexhaustive-depsor useuseEffectEventfrom'react'(not'common', nevereslint-disable). - Modularity & refactoring — Split components around ~200–300 lines; co-locate sub-components, avoid barrel files, and extract non-trivial pure logic to
.utils.ts(keep static copy in.tsx, unit-test only real edge cases). Update importers directly (no re-export shims) and delete dead code. - Composition & React 19 — Prefer
children, compound components, and explicit variants over boolean-prop proliferation or render props, and passrefas a regular prop in new React 19 components. - Types & fetch rendering — Model multi-state values as discriminated unions and name booleans
is/has/can/should. Never nest ternaries — render fetch states with early returns or mutually exclusive sibling&&blocks (isPending→isError→ empty → data). - Naming & memoization — Prop callbacks are
onX, internal handlershandleX. Custom hooks returnuseMemo-wrapped objects (not tuples); otherwise memoize only for measured cost or referential stability. - Runtime matrix & blast radius — Verify platform vs self-hosted, flag on/off, plan/provider/branch, and permissions; subtract only the exact condition when relaxing a guard. Fire each side effect in one layer and update companion surfaces together.
Non-deducible repo traps
- CI-only gates —
pnpm --filter studio run lint:ratchet(warning counts cannot increase) andpnpm knip --workspace apps/studio(dead files/deps; no inlineknip-ignore— add unimported entry files toknip.jsoncentry, or temporary stacked-PR files toignoreIssueswithused from #NNN). ?error=query param — Never use?error=as a custom URL param:auth-jsinAuthProviderintercepts it across all Studio pages and fires a spurious error toast.copyToClipboard(ui) — Neverawaitbefore calling it (Safari gesture rule, lint-enforced — pass aPromise<string>as the 1st arg). It catches errors internally, so run post-copy feedback (toast.success,setCopied) in its 2nd callback arg, never afterawait.- Params & permissions — Inside
components/**,useParams()comes from'common'(camelCases kebab-case keys, merges search + route params, returnsstring | undefined); insideroutes/**, useRoute.useParams()(don't mix both in the same file).useAsyncCheckPermissions(hooks/misc/useCheckPermissions) returnscan: trueself-hosted. - Feature & cloud gating —
useIsFeatureEnabled(product features) anduseFlagfrom'common'(ConfigCat flags) are separate systems.useIsAwsCloudProvider(hooks/misc/useSelectedProject) matchesAWSonly — also checkuseIsAwsK8sCloudProvider/useIsAwsNimbusCloudProviderfor AWS-hosted features. - Icons, dates, toasts & SQL —
lucide-reacticons import*Icondirectly (neverCheck as CheckIconaliases); usedayjs(plugins pre-loaded inroutes/__root.tsx),toastfrom'sonner', andexecuteSql(data/sql/execute-sql-mutation) for ad-hoc Postgres SQL.