Repository navigation
build(studio): Vite/TanStack-Start build pipeline behind flag (stack 1/6, from #46424) - #47107
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
Disabled knowledge base sources:
📝 WalkthroughWalkthroughAdds TanStack Start as a parallel runtime alongside Next.js in ChangesTanStack Start parallel runtime infrastructure
Sequence Diagram(s)sequenceDiagram
participant CLI
participant dispatch.js
participant serve.js
participant start.ts
participant hosted-api-allowlist.ts
CLI->>dispatch.js: pnpm dev/build/start
dispatch.js->>dispatch.js: resolve STUDIO_FRAMEWORK from env files
dispatch.js->>serve.js: spawn pnpm run <target>:<framework>
CLI->>serve.js: HTTP request
serve.js->>serve.js: serve static file or bridge Node request
serve.js->>start.ts: call TanStack fetch handler
start.ts->>hosted-api-allowlist.ts: check hosted /api/* path
alt unsupported hosted endpoint
start.ts-->>serve.js: 404 JSON response
else supported path
start.ts-->>serve.js: Web Response
end
serve.js-->>CLI: streamed Node response
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
🎭 Playwright Test ResultsDetails
Flaky testsFeatures › realtime-inspector.spec.ts › Realtime Inspector › Basic Inspector UI › channel selection popover opens and works Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
…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.
6fc4bc3 to
5326d10
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/scripts/serve.js`:
- Around line 151-153: The loop at line 152 that sets response headers using
res.setHeader(k, v) overwrites duplicate header keys, causing all but the last
Set-Cookie header to be lost when proxying responses. Replace the res.setHeader
call with res.appendHeader to properly append headers instead of overwriting
them, which will preserve all Set-Cookie headers and maintain
authentication/session flows.
In `@apps/studio/turbo.jsonc`:
- Around line 129-134: The outputs array in the turbo.jsonc file contains a
trailing comma after "dist/**" which is invalid JSON syntax and causes a parse
error. Remove the trailing comma from the last element in the outputs array so
that "dist/**" appears without a comma, allowing the JSON parser to correctly
recognize the closing bracket of the array.
🪄 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: eeb37489-8949-4a40-8aa7-10c472de7927
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (38)
.prettierignoreapps/design-system/package.jsonapps/docs/package.jsonapps/studio/.gitignoreapps/studio/TANSTACK_MIGRATION.mdapps/studio/components/interfaces/Connect/content/nextjs/app/supabasejs/content.tsxapps/studio/components/interfaces/Database/Replication/Destinations.tsxapps/studio/components/interfaces/Organization/BillingSettings/Subscription/CancellationFlow.tsxapps/studio/components/ui/AIEditor/index.tsxapps/studio/data/utils/deployment-commit-query.tsapps/studio/eslint.config.cjsapps/studio/hooks/use-check-latest-deploy.tsxapps/studio/lib/ai/util.tsapps/studio/lib/hosted-api-allowlist.tsapps/studio/lib/role-impersonation.tsapps/studio/lib/telemetry.tsxapps/studio/next.config.tsapps/studio/package.jsonapps/studio/proxy.tsapps/studio/redirects.shared.tsapps/studio/scripts/dispatch.jsapps/studio/scripts/ratchet-eslint-rules.tsapps/studio/scripts/serve.jsapps/studio/scripts/smoke-server.mjsapps/studio/start.tsapps/studio/styles/fonts.cssapps/studio/tsconfig.jsonapps/studio/turbo.jsoncapps/studio/vercel.tsapps/studio/vite.config.tsapps/ui-library/package.jsonpackage.jsonpackages/ui-patterns/package.jsonpackages/ui/src/components/AnimatedCounter/AnimatedCounter.tsxpackages/ui/src/components/Typography/Typography.tsxpnpm-workspace.yamlscripts/generateLocalEnv.jsturbo.jsonc
💤 Files with no reviewable changes (2)
- packages/ui/src/components/Typography/Typography.tsx
- apps/studio/components/interfaces/Connect/content/nextjs/app/supabasejs/content.tsx
There was a problem hiding this comment.
♻️ Duplicate comments (2)
apps/studio/turbo.jsonc (1)
129-134:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winFix parse-breaking trailing comma in
outputs.The trailing comma after
"dist/**"(Line 133) causes a parse error at Line 134 in current tooling, which blocks safe merge/CI config parsing.Proposed minimal fix
"outputs": [ ".next/**", "!.next/cache/**", "!.next/dev/**/*", - "dist/**", + "dist/**" ],#!/bin/bash set -euo pipefail python - <<'PY' from pathlib import Path import re, sys p = Path("apps/studio/turbo.jsonc") t = p.read_text() m = re.search(r'"outputs"\s*:\s*\[(?s).*?"dist/\*\*",\s*\]', t) print("trailing_comma_in_outputs =", bool(m)) sys.exit(1 if m else 0) PY🤖 Prompt for 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. In `@apps/studio/turbo.jsonc` around lines 129 - 134, The outputs array in the turbo.jsonc file contains a trailing comma after the "dist/**" entry that causes parse errors in the JSON configuration. Remove the trailing comma that appears after "dist/**" in the outputs array to fix the parse error and allow safe configuration parsing by the tooling.Source: Linters/SAST tools
apps/studio/scripts/serve.js (1)
150-153:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPreserve multi-value
Set-Cookieheaders when proxying.At Line 152, iterating headers and calling
res.setHeader(k, v)overwrites duplicate keys. This can drop all but oneSet-Cookieheader and break auth/session flows.Proposed minimal fix
async function pipeWebResponse(response, res) { res.statusCode = response.status - for (const [k, v] of response.headers) res.setHeader(k, v) + const setCookies = + typeof response.headers.getSetCookie === 'function' ? response.headers.getSetCookie() : [] + for (const [k, v] of response.headers) { + if (k.toLowerCase() === 'set-cookie') continue + res.setHeader(k, v) + } + if (setCookies.length > 0) res.setHeader('set-cookie', setCookies) if (!response.body) { res.end() return }#!/bin/bash set -euo pipefail rg -n "for \\(const \\[k, v\\] of response\\.headers\\) res\\.setHeader\\(k, v\\)" apps/studio/scripts/serve.js rg -n "set-cookie|getSetCookie|appendHeader" apps/studio/scripts/serve.js🤖 Prompt for 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. In `@apps/studio/scripts/serve.js` around lines 150 - 153, In the pipeWebResponse function, the loop iterating through response.headers and calling res.setHeader(k, v) overwrites duplicate header keys instead of preserving them, which breaks Set-Cookie headers needed for authentication. Modify the header handling logic to detect multi-value headers (particularly Set-Cookie) and use res.appendHeader instead of res.setHeader when a header with the same key already exists, or use the appropriate Node.js method that supports multiple values for the same header key.
🤖 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.
Duplicate comments:
In `@apps/studio/scripts/serve.js`:
- Around line 150-153: In the pipeWebResponse function, the loop iterating
through response.headers and calling res.setHeader(k, v) overwrites duplicate
header keys instead of preserving them, which breaks Set-Cookie headers needed
for authentication. Modify the header handling logic to detect multi-value
headers (particularly Set-Cookie) and use res.appendHeader instead of
res.setHeader when a header with the same key already exists, or use the
appropriate Node.js method that supports multiple values for the same header
key.
In `@apps/studio/turbo.jsonc`:
- Around line 129-134: The outputs array in the turbo.jsonc file contains a
trailing comma after the "dist/**" entry that causes parse errors in the JSON
configuration. Remove the trailing comma that appears after "dist/**" in the
outputs array to fix the parse error and allow safe configuration parsing by the
tooling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 0c162133-79c9-431d-9fc4-59e6bdd1b3e3
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (37)
.prettierignoreapps/design-system/package.jsonapps/docs/package.jsonapps/studio/.gitignoreapps/studio/TANSTACK_MIGRATION.mdapps/studio/components/interfaces/Connect/content/nextjs/app/supabasejs/content.tsxapps/studio/components/interfaces/Database/Replication/Destinations.tsxapps/studio/components/interfaces/Organization/BillingSettings/Subscription/CancellationFlow.tsxapps/studio/components/ui/AIEditor/index.tsxapps/studio/data/utils/deployment-commit-query.tsapps/studio/hooks/use-check-latest-deploy.tsxapps/studio/lib/ai/util.tsapps/studio/lib/hosted-api-allowlist.tsapps/studio/lib/role-impersonation.tsapps/studio/lib/telemetry.tsxapps/studio/next.config.tsapps/studio/package.jsonapps/studio/proxy.tsapps/studio/redirects.shared.tsapps/studio/scripts/dispatch.jsapps/studio/scripts/ratchet-eslint-rules.tsapps/studio/scripts/serve.jsapps/studio/scripts/smoke-server.mjsapps/studio/start.tsapps/studio/styles/fonts.cssapps/studio/tsconfig.jsonapps/studio/turbo.jsoncapps/studio/vercel.tsapps/studio/vite.config.tsapps/ui-library/package.jsonpackage.jsonpackages/ui-patterns/package.jsonpackages/ui/src/components/AnimatedCounter/AnimatedCounter.tsxpackages/ui/src/components/Typography/Typography.tsxpnpm-workspace.yamlscripts/generateLocalEnv.jsturbo.jsonc
💤 Files with no reviewable changes (2)
- packages/ui/src/components/Typography/Typography.tsx
- apps/studio/components/interfaces/Connect/content/nextjs/app/supabasejs/content.tsx
✅ Files skipped from review due to trivial changes (6)
- packages/ui/src/components/AnimatedCounter/AnimatedCounter.tsx
- apps/studio/.gitignore
- apps/studio/lib/ai/util.ts
- .prettierignore
- apps/studio/components/interfaces/Organization/BillingSettings/Subscription/CancellationFlow.tsx
- apps/ui-library/package.json
🚧 Files skipped from review as they are similar to previous changes (23)
- apps/studio/lib/telemetry.tsx
- apps/design-system/package.json
- apps/studio/scripts/smoke-server.mjs
- turbo.jsonc
- apps/studio/lib/hosted-api-allowlist.ts
- apps/studio/tsconfig.json
- apps/studio/hooks/use-check-latest-deploy.tsx
- apps/studio/data/utils/deployment-commit-query.ts
- apps/studio/proxy.ts
- pnpm-workspace.yaml
- packages/ui-patterns/package.json
- apps/docs/package.json
- apps/studio/start.ts
- scripts/generateLocalEnv.js
- apps/studio/scripts/ratchet-eslint-rules.ts
- apps/studio/lib/role-impersonation.ts
- apps/studio/components/interfaces/Database/Replication/Destinations.tsx
- apps/studio/components/ui/AIEditor/index.tsx
- package.json
- apps/studio/redirects.shared.ts
- apps/studio/package.json
- apps/studio/vite.config.ts
- apps/studio/vercel.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.
| @@ -0,0 +1,144 @@ | |||
| import { routes, type Redirect, type VercelConfig } from '@vercel/config/v1' | |||
There was a problem hiding this comment.
Not sure why we need this config, but don't we need to follow this guide https://tanstack.com/start/latest/docs/framework/react/guide/hosting#nitro?
There was a problem hiding this comment.
If we use nitro we'll be running a Vercel function on every request – so I've opted for a simpler, pure SPA approach
| process.exit(2) | ||
| } | ||
|
|
||
| function readEnvLocalKey(key) { |
There was a problem hiding this comment.
We should just use dotenv here, no need for this magic. I tried adding the env var in .env first, so got confused why it didn't work.
There was a problem hiding this comment.
Yeah makes sense – the real issue was dispatch.js only reading .env.local, while serve.js reads .env too, so anything in .env got silently ignored. Fixed it to read both now (shell > .env.local > .env, same as serve.js/vite).
On dotenv – I actually started this PR by loading the whole env in, but that's exactly what caused problems: it clobbers the dispatcher-set values like the e2e NEXT_PUBLIC_IS_PLATFORM override, which is why it ended up only pulling the one key.
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.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/scripts/lib/env.js`:
- Around line 41-44: The bare catch block in the readFileSync error handling
swallows all filesystem errors including permission and IO errors, which can
silently drop environment values. Modify the catch block to check if the caught
error has a code property equal to ENOENT (file not found), and only then
continue; for all other errors (permission denied, IO errors, etc.), rethrow the
error to prevent silent failures. This ensures only missing files are gracefully
skipped while real filesystem failures are properly surfaced.
🪄 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: c685b0cd-e08c-4e0c-89a8-6cf6573e84f1
📒 Files selected for processing (3)
apps/studio/scripts/dispatch.jsapps/studio/scripts/lib/env.jsapps/studio/scripts/serve.js
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/studio/scripts/serve.js
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.
dnywh
left a comment
There was a problem hiding this comment.
Tested an instance of @tanstack/react-table on staging: PlatformWebhooksEndpointDetails.
**Stack 2/6** of the TanStack Start migration (#46424). Stacked on **#47107** (S1) — review that first; this PR's diff is just the compat shims. > [!NOTE] > Purely additive. Next never imports these files — under TanStack they're wired in via Vite aliases (`next/*` → `@/compat/next/*`). No routes consume them yet (that begins in stack 3). ## What's in this PR `apps/studio/compat/next/*` — drop-in shims so the existing pages-router code runs unchanged under TanStack Start: - `link`, `router`, `navigation`, `head`, `image`, `legacy/image`, `script`, `dynamic`, `server`, `_router-events` — React/runtime shims over `@tanstack/react-router`. - `api.ts` — `toWebHandler`, which adapts a pages-router API handler `(req, res)` into a TanStack server-route Web `fetch` handler. ## Verification On top of S1: `studio` typecheck ✓, lint (0 errors) ✓. Next build is unaffected (nothing imports these under tsc). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added broad Next.js compatibility support for routing, links, dynamic imports, images, scripts, head metadata, navigation hooks, server responses, and API handlers. * Improved handling of redirects, pathname/search params, base paths, and event callbacks for smoother app behavior. * **Tests** * Added coverage for URL resolution and dynamic route interpolation to verify Next-style routing behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alaister Young <[email protected]> Co-authored-by: Ivan Vasilov <[email protected]>
) (#47119) **Stack 6/6 (final)** of the TanStack Start migration (#46424). The middle slices (#47107 → #47118) have all merged, so this now sits directly on master. ## What's in this PR One file: `.github/workflows/studio-e2e-test.yml` — adds `framework: [next, tanstack]` to the test/report matrices and sets `STUDIO_FRAMEWORK` (consumed by `scripts/dispatch.js`). Until now CI only built/tested Next. This flips on the dual-framework E2E matrix so the TanStack build gets exercised end-to-end on every run. ##⚠️ Depends on #47657 (merge that first) The `tanstack` shard needs the Monaco loader fix in **#47657** to be on master. Quick version: master's #47182 re-nested the Monaco assets under `public/monaco-editor/vs/` and the TanStack root was still pointing at the old flat path, so Monaco didn't mount anywhere in the TanStack build and every editor-backed test timed out (RLS, cron SQL, realtime JSON, db functions, GraphiQL). Kept that fix on its own branch rather than piling it onto this one. Merge order: 1. #47657 → master 2. re-merge master into here (I'll cascade it) 3. `tanstack` shard goes green → merge this ##⚠️ Branch-protection note This renames the E2E jobs (`E2E tests` → `E2E tests (next|tanstack, shard)`), so master's current required status checks (`E2E tests (1, 2)` / `(2, 2)`) stop being reported. The required-check list in branch protection needs updating to the new names when this merges. ## Verification Config-only, no app code. The real validation is this matrix running both shards green once #47657 lands — the `next` shards already pass here; the `tanstack` shards pass once the Monaco fix is on master. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Integration overview markdown can now be loaded more reliably from a synchronized on-disk registry (raw markdown support). * **Bug Fixes** * Navigation, redirects, and prefetch now preserve query strings and hash fragments more consistently using Next-like semantics (including repeated keys, empty clearing, and lossless encoding like newlines). * Improved internal-link/router compatibility for Next-style `?`/`#` targets and base-path handling. * Edge Functions diff tab matching works correctly in the browser without Node-specific path utilities. <!-- 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 1/6 of the TanStack Start migration (#46424), split into reviewable, independently-mergeable PRs.
Important
Next stays the default and only active framework after this PR. This wires up the Vite/TanStack-Start build pipeline behind the
STUDIO_FRAMEWORKflag, but there are no TanStack routes yet — so the TanStack build isn't functional or tested until later PRs in the stack. Nothing about the Next build, dev, or deploy changes behaviourally here.What's in this PR
dev/build/startnow go throughscripts/dispatch.js, which runs the Next variant unlessSTUDIO_FRAMEWORK=tanstack. The original commands are preserved asdev:next/build:next/start:next.vite.config.ts,serve.js,smoke-server.mjs, vite/tanstack deps,turbo.jsonc.tsconfig.json:jsx: react-jsx,moduleResolution: Bundler,target: ES2022. Becauseincludeis**/*.ts(x), this re-typechecks the whole app, so the companion adaptations below land with it.BufferSourcecasts,packages/uiunused-Reactimport removals, etc.next.config.ts+redirects.shared.ts(redirect rules now shared withvercel.ts),proxy.ts/start.tsmiddleware +hosted-api-allowlist.ts.Verification
Run locally off
master: frozen install ✓,studiotypecheck ✓, Next build ✓ (compiles + generates all routes), lint ratchet ✓ ("some rules improved"), prettier ✓.Summary by CodeRabbit
New Features
/api/*paths.Improvements
Dependencies
Documentation / Chores