Repository navigation
feat(studio): port API handlers to TanStack server routes (stack 4/6, from #46424) - #47113
Conversation
…RAMEWORK flag (1/6, from #46424) Foundation of the TanStack Start migration (#46424), split into a reviewable stack. Next remains the default and only active framework after this PR — the TanStack build pipeline is wired up but has no routes yet, so it isn't functional or tested until later PRs flip the feature flag. - package.json: dev/build/start now dispatch via scripts/dispatch.js (defaults to next); add :next/:tanstack variants, vite/tanstack deps. - scripts: dispatch.js, serve.js, smoke-server.mjs, generateLocalEnv.js. - vite.config.ts, turbo.jsonc, tsconfig.json (jsx: react-jsx, Bundler). - next.config.ts + redirects.shared.ts (shared redirect rules with vercel.ts), proxy.ts/start.ts middleware + hosted-api-allowlist.ts. - companion adaptations the tsconfig change requires to keep typecheck green (BufferSource casts, packages/ui unused-React import removals, etc.). Verified: frozen install, studio typecheck, Next build, and lint ratchet all green; Next stays the default build.
…46424) Adds compat/next/* — drop-in shims for next/link, next/router, next/navigation, next/head, next/image, next/script, next/dynamic, next/server, and a toWebHandler (compat/next/api.ts) that lets pages-router API handlers run as TanStack server routes. Under TanStack these are wired in via Vite aliases (next/* -> @/compat/next/*); Next never imports them, so this is purely additive. No routes consume them yet — that starts in the next stack PR. Stacked on #47107. Verified: studio typecheck + lint (0 errors).
…outes (stack 3/6, from #46424) Adds the TanStack Start app skeleton: routes/__root.tsx (root layout + redirect beforeLoad), router.tsx, and the _auth (sign-in/up, forgot/reset password, SSO/MFA/partner, CLI login) and _app (account, org/$slug, support) route trees. These are thin wrappers that render the existing pages-router page components via the compat shims from #47110. routeTree.gen.ts is REGENERATED by the tanstackStart vite plugin for exactly the routes present in this PR (not copied from the migration branch, whose tree references all ~300 routes) — so it typechecks standalone. API routes and project routes (and a full regenerated tree) land in the next stack PRs. Stacked on #47110. Verified: studio typecheck + lint (0 errors). Next is unaffected (it builds pages/, ignores routes/).
…outes (stack 4/6, from #46424) Adds routes/api/** — ~104 thin TanStack server routes, each wrapping the existing pages/api handler via toWebHandler (compat shim from S2). Mechanical and homogeneous: createFileRoute(...).server.handlers = { METHOD: handler }. Covers platform (pg-meta, auth, storage, integrations, telemetry, ...), ai, v1, connect, content/mcp, and the standalone utility endpoints. routeTree.gen.ts is REGENERATED for the routes now present (root + auth/app + api). Project page routes + the full tree land in stack 5. Stacked on #47112. Verified: studio typecheck + lint (0 errors). Next is unaffected (builds pages/, ignores routes/).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
🎭 Playwright Test ResultsDetails
Flaky testsFeatures › realtime-inspector.spec.ts › Realtime Inspector › Message Display › messages counter shows correct count Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/studio/routes/api/mcp/index.ts`:
- Around line 90-93: The catch block in the MCP API route handler is directly
embedding the raw error object in the JSON response through the `cause` field,
which can fail when the error is circular or non-serializable, breaking the
error handling path itself. Instead of passing the raw `err` object to
JSON.stringify, convert it to a safe string representation by using either
`err.message`, `String(err)`, or similar safe primitive that captures the error
information without risk of serialization failure.
In `@apps/studio/routes/api/platform/pg-meta/`$ref/query/index.ts:
- Line 8: The route path in the createFileRoute call has a trailing slash that
makes it inconsistent with other API route declarations and causes 404 errors
when callers attempt to reach the endpoint without the trailing slash. Remove
the trailing slash from the route path string in the createFileRoute call,
changing '/api/platform/pg-meta/$ref/query/' to
'/api/platform/pg-meta/$ref/query' to ensure the endpoint matches requests with
and without trailing slashes.
In `@apps/studio/routes/api/v1/projects/`$ref/functions/$slug/body.ts:
- Around line 43-94: The multipart body stream reads and enqueues all file
chunks eagerly in the start() method without respecting backpressure or handling
cancellation, causing potential memory buffering and file handle leaks. Replace
the ReadableStream constructor with an async generator function that yields the
metadata, file headers, file content chunks, and boundaries sequentially, then
wrap it with Readable.from() to create the stream. The async generator approach
will naturally handle backpressure by pausing when the consumer can't keep up
and respect cancellation when the stream is destroyed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 22a7963b-f16f-4deb-9756-dac657c33245
📒 Files selected for processing (105)
apps/studio/routeTree.gen.tsapps/studio/routes/api/ai/code/complete.tsapps/studio/routes/api/ai/docs.tsapps/studio/routes/api/ai/feedback/classify.tsapps/studio/routes/api/ai/feedback/rate.tsapps/studio/routes/api/ai/onboarding/design.tsapps/studio/routes/api/ai/sql/check-api-key.tsapps/studio/routes/api/ai/sql/cron-v2.tsapps/studio/routes/api/ai/sql/filter-v1.tsapps/studio/routes/api/ai/sql/generate-v4.tsapps/studio/routes/api/ai/sql/parse-client-code.tsapps/studio/routes/api/ai/sql/policy.tsapps/studio/routes/api/ai/sql/title-v2.tsapps/studio/routes/api/check-cname.tsapps/studio/routes/api/cli-release-version.tsapps/studio/routes/api/connect/index.tsapps/studio/routes/api/content/graphql.tsapps/studio/routes/api/edge-functions/test.tsapps/studio/routes/api/enabled-features-overrides.tsapps/studio/routes/api/generate-attachment-url.tsapps/studio/routes/api/get-deployment-commit.tsapps/studio/routes/api/get-ip-address.tsapps/studio/routes/api/get-s3-keys.tsapps/studio/routes/api/get-utc-time.tsapps/studio/routes/api/incident-banner.tsapps/studio/routes/api/incident-status.tsapps/studio/routes/api/integrations/stripe-sync.tsapps/studio/routes/api/mcp/index.tsapps/studio/routes/api/parse-query.tsapps/studio/routes/api/platform/auth/$ref/invite.tsapps/studio/routes/api/platform/auth/$ref/magiclink.tsapps/studio/routes/api/platform/auth/$ref/otp.tsapps/studio/routes/api/platform/auth/$ref/recover.tsapps/studio/routes/api/platform/auth/$ref/users/$id/factors.tsapps/studio/routes/api/platform/auth/$ref/users/$id/index.tsapps/studio/routes/api/platform/auth/$ref/users/index.tsapps/studio/routes/api/platform/database/$ref/pooling.tsapps/studio/routes/api/platform/deployment-mode.tsapps/studio/routes/api/platform/integrations/$slug.tsapps/studio/routes/api/platform/integrations/github/authorization.tsapps/studio/routes/api/platform/integrations/github/connections.tsapps/studio/routes/api/platform/integrations/github/repositories.tsapps/studio/routes/api/platform/organizations/$slug/billing/subscription.tsapps/studio/routes/api/platform/organizations/index.tsapps/studio/routes/api/platform/pg-meta/$ref/column-privileges.tsapps/studio/routes/api/platform/pg-meta/$ref/extensions.tsapps/studio/routes/api/platform/pg-meta/$ref/foreign-tables.tsapps/studio/routes/api/platform/pg-meta/$ref/materialized-views.tsapps/studio/routes/api/platform/pg-meta/$ref/policies.tsapps/studio/routes/api/platform/pg-meta/$ref/publications.tsapps/studio/routes/api/platform/pg-meta/$ref/query/index.tsapps/studio/routes/api/platform/pg-meta/$ref/tables.tsapps/studio/routes/api/platform/pg-meta/$ref/triggers.tsapps/studio/routes/api/platform/pg-meta/$ref/types.tsapps/studio/routes/api/platform/pg-meta/$ref/views.tsapps/studio/routes/api/platform/profile/index.tsapps/studio/routes/api/platform/projects/$ref/analytics/endpoints/$name.tsapps/studio/routes/api/platform/projects/$ref/analytics/log-drains.tsapps/studio/routes/api/platform/projects/$ref/analytics/log-drains/$uuid.tsapps/studio/routes/api/platform/projects/$ref/api-keys/temporary.tsapps/studio/routes/api/platform/projects/$ref/api/graphql.tsapps/studio/routes/api/platform/projects/$ref/api/rest.tsapps/studio/routes/api/platform/projects/$ref/billing/addons.tsapps/studio/routes/api/platform/projects/$ref/config/index.tsapps/studio/routes/api/platform/projects/$ref/config/postgrest.tsapps/studio/routes/api/platform/projects/$ref/config/secrets/update-status.tsapps/studio/routes/api/platform/projects/$ref/content/count.tsapps/studio/routes/api/platform/projects/$ref/content/folders/$id.tsapps/studio/routes/api/platform/projects/$ref/content/folders/index.tsapps/studio/routes/api/platform/projects/$ref/content/index.tsapps/studio/routes/api/platform/projects/$ref/content/item/$id.tsapps/studio/routes/api/platform/projects/$ref/databases.tsapps/studio/routes/api/platform/projects/$ref/index.tsapps/studio/routes/api/platform/projects/$ref/infra-monitoring.tsapps/studio/routes/api/platform/projects/$ref/run-lints.tsapps/studio/routes/api/platform/projects/$ref/settings.tsapps/studio/routes/api/platform/projects/index.tsapps/studio/routes/api/platform/props/org/$slug.tsapps/studio/routes/api/platform/props/project/$ref/api.tsapps/studio/routes/api/platform/props/project/$ref/index.tsapps/studio/routes/api/platform/storage/$ref/buckets/$id/empty.tsapps/studio/routes/api/platform/storage/$ref/buckets/$id/index.tsapps/studio/routes/api/platform/storage/$ref/buckets/$id/objects/download.tsapps/studio/routes/api/platform/storage/$ref/buckets/$id/objects/index.tsapps/studio/routes/api/platform/storage/$ref/buckets/$id/objects/list.tsapps/studio/routes/api/platform/storage/$ref/buckets/$id/objects/move.tsapps/studio/routes/api/platform/storage/$ref/buckets/$id/objects/public-url.tsapps/studio/routes/api/platform/storage/$ref/buckets/$id/objects/sign-multi.tsapps/studio/routes/api/platform/storage/$ref/buckets/$id/objects/sign.tsapps/studio/routes/api/platform/storage/$ref/buckets/index.tsapps/studio/routes/api/platform/storage/$ref/vector-buckets/$id/index.tsapps/studio/routes/api/platform/storage/$ref/vector-buckets/$id/indexes/$indexName.tsapps/studio/routes/api/platform/storage/$ref/vector-buckets/$id/indexes/index.tsapps/studio/routes/api/platform/storage/$ref/vector-buckets/index.tsapps/studio/routes/api/platform/telemetry/event.tsapps/studio/routes/api/status-override.tsapps/studio/routes/api/v1/projects/$ref/api-keys.tsapps/studio/routes/api/v1/projects/$ref/api-keys/$id.tsapps/studio/routes/api/v1/projects/$ref/config/auth/signing-keys/index.tsapps/studio/routes/api/v1/projects/$ref/config/auth/signing-keys/legacy.tsapps/studio/routes/api/v1/projects/$ref/database/migrations.tsapps/studio/routes/api/v1/projects/$ref/functions/$slug/body.tsapps/studio/routes/api/v1/projects/$ref/functions/$slug/index.tsapps/studio/routes/api/v1/projects/$ref/functions/index.tsapps/studio/routes/api/v1/projects/$ref/types/typescript.ts
Iterating response.headers and calling res.setHeader collapses duplicate keys; for set-cookie the Headers iterator joins every cookie into one comma-separated value, corrupting auth/session cookies. Pull cookies out via getSetCookie() and set them as an array. Addresses PR review feedback.
The navigate() shim overloaded Next's `shallow` option as the
push-vs-replace signal, but the ternary was inverted so replace() did a
push. Inverting it naively would also break the 5 push(url, { shallow:
true }) call sites, since shallow is a real Next option (no-op here) and
has nothing to do with push vs replace. Use a dedicated internal
`_replace` flag instead, matching Next's pages-router where push always
pushes and replace always replaces regardless of shallow.
Addresses PR review feedback.
The Next pages pass inboundFlow to SignInLayout (sign-in -> 'sign-in', sign-up -> 'sign-up'), which gates the focused-provider interstitial and destination-branded heading for inbound auth links. The TanStack route wrappers dropped it. sign-in-sso intentionally left unchanged — its Next page doesn't pass inboundFlow either. Addresses PR review feedback.
…backpressure - mcp: stringify the non-Error throw in the 500 fallback instead of embedding the raw value, so a circular/non-serializable cause can't make JSON.stringify throw inside the catch. - functions body: build the multipart stream from an async generator via Readable.from(...).toWeb() so file reads honour consumer backpressure and close the file handle on client disconnect, instead of eagerly buffering every file in ReadableStream.start(). Addresses PR review feedback.
Extract the .env parser into scripts/lib/env.js so dispatch.js and serve.js use one implementation instead of duplicating the regex. dispatch.js now reads .env as well as .env.local (matching serve.js / vite precedence: shell > .env.local > .env), so STUDIO_FRAMEWORK set in .env is picked up — previously only .env.local was read, which is why setting it in .env silently did nothing. Addresses PR review feedback.
readEnvFiles swallowed every readFileSync error, so an existing-but- unreadable env file (bad permissions, IO error) was silently treated as absent — dropping its values and potentially booting serve.js without secrets like POSTGRES_PASSWORD. Skip only ENOENT and rethrow the rest. Addresses PR review feedback.
The Vercel SPA catch-all rewrite (`${prefix}/(.*)` -> /_shell) swallowed
missing extensioned paths, so a stale hashed chunk (e.g. requested after a
redeploy) returned text/html 200 instead of 404. The browser then threw
'Failed to load module script ... MIME type text/html', and because /assets/*
is cached immutable the bogus HTML poisoned the edge cache under the asset URL
(defeating skew protection, which is served after the cache).
Make the shell rewrite match only extensionless paths via a negative lookahead
so a missing file with an extension 404s cleanly — letting skew protection's
__vdpl routing serve the chunk from the deployment that still has it, or the
client's vite:preloadError backstop recover.
New org settings page added to master after the initial migration sweep; wraps OrganizationSettingsLayout like the sibling audit route. Route tree regenerated.
useUrlState (table sort/filter) pushes { pathname: router.pathname, query }
where router.pathname is the bracketed route pattern (/project/[ref]/...).
Next's pages-router fills [ref]/[id] from query and drops them from the query
string; the compat shim just concatenated, so TanStack navigated to a LITERAL
/project/[ref]/... — no project matched (ref === '[ref]') and it bounced to a
'project not found' redirect. Most visible on column rename, which rewrites
sort/filter URL state after a successful (correct) rename.
resolveUrl now interpolates [name] / [...name] / [[...name]] from query and
removes the consumed keys, mirroring Next. String URLs and bracket-free
pathnames are unchanged.
Fixes the redirect and the database.spec column-CRUD e2e on the tanstack build.
Adds a unit test guarding the dynamic-param interpolation in the next/router shim (the fix for the column-rename redirect), since the shim has been fragile to changes. Exports resolveUrl for testing only.
# Conflicts: # apps/studio/routeTree.gen.ts
| // object would make JSON.stringify throw inside the catch and turn this | ||
| // into an unhandled 500. | ||
| return new Response( | ||
| JSON.stringify({ error: 'Unable to process MCP request', cause: String(err) }), |
There was a problem hiding this comment.
Leaving this as-is — it's a false positive. Line 95 is only reached for non-Error throws (the instanceof Error branch returns above it), and a non-Error value has no stack to expose. The Error branch only returns .message, never .stack. This is also a faithful port of the existing pages/api/mcp handler, just hardened with String(). Dismissing as won't-fix.
Braintrust eval report
|
…rom #46424) (#47117) **Stack 5.1/6** of the TanStack Start migration (#46424). The original S5 (174 files) was over CodeRabbit's 150-file review cap, so it's split into 5.1 + 5.2 by product. Stacked on **#47113** (S4). > [!NOTE] > Thin route wrappers rendering the existing pages-router components via compat shims. Next-safe (full Next build run). The TanStack app isn't functional end-to-end until 5.2 + the matrix flip. ## What's in this PR - **Data-cluster project routes:** database, editor, sql, storage, realtime, branches. - **Top-level / onboarding routes:** `authorize`, `join`, `logout`, `redeem`, `verify-email`, `claim-project`, aws-marketplace, Vercel/GitHub integration entrypoints; `_app`/`_auth` layout shells; `/org/_` + `/project/_` catch-alls. - **Supporting edits:** hoist `BranchesPageWrapper` out of `getLayout`, `ConnectStepsSection` `import.meta.glob`, `api/server.js`. - `routeTree.gen.ts` regenerated for the routes present so far. ## Verification On top of S1–S4: `studio` typecheck ✓, lint (0 errors) ✓, **Next build ✓ (181/181 pages)**. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Restructured application routing infrastructure for improved code organization and maintainability. * Extracted and refactored layout wrapper components for enhanced reusability across different sections of the application. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alaister Young <[email protected]> Co-authored-by: Ivan Vasilov <[email protected]>
Stack 4/6 of the TanStack Start migration (#46424). Stacked on #47112 (S3).
Note
Mechanical and homogeneous — every file is the same shape: a
createFileRoute(...)whoseserver.handlersdelegate to the existingpages/apihandler viatoWebHandler(the compat shim from S2). The pages-router handlers are unchanged; Next still serves them directly and ignoresroutes/.What's in this PR
routes/api/**(~104 files): platform (pg-meta, auth, storage, integrations, profile, telemetry, organizations, projects…),ai/*,v1/*,connect,content/mcp, and standalone endpoints (deployment-mode,get-ip-address, etc.).routeTree.gen.ts— regenerated for the routes present so far (root + auth/app + api).Review tip
The route files are near-identical wrappers, so this is fast to skim. The generated
routeTree.gen.tsisn't meaningful review surface.Verification
On top of S1–S3:
studiotypecheck ✓, lint (0 errors) ✓.Summary by CodeRabbit
New Features
Chores