Repository navigation
build(studio): Next-compat shims (stack 2/6, from #46424) - #47110
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).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a complete ChangesNext.js Compatibility Layer
Sequence Diagram(s)sequenceDiagram
participant WebRuntime
participant toWebHandler
participant buildRequest
participant buildResponse
participant NextHandler
WebRuntime->>toWebHandler: Request + routeParams
toWebHandler->>buildRequest: build NextApiRequest proxy
buildRequest-->>toWebHandler: req (headers, cookies, query, body, signal→events)
toWebHandler->>buildResponse: build NextApiResponse proxy
buildResponse-->>toWebHandler: res + finalize()
toWebHandler->>NextHandler: handler(req, res)
NextHandler->>buildResponse: res.writeHead / res.json / res.end
toWebHandler->>buildResponse: finalize()
buildResponse-->>toWebHandler: Response (buffered or streaming)
toWebHandler-->>WebRuntime: Response
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
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/compat/next/router.ts`:
- Around line 174-183: The ternary operator logic in the navigate function is
inverted. When shallow is true (indicating a replace operation), the current
code sets replace to false instead of true. Fix this by inverting the ternary
operator so that when options?.shallow is truthy, replace is set to true, and
when it's falsy, replace is set to undefined. This ensures that when replace()
is called with shallow: true, the router.navigate call will actually perform a
replace operation instead of a push.
🪄 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: 595bcab0-fe8e-453d-ad8a-b6b6fddce9d5
📒 Files selected for processing (12)
apps/studio/compat/next/_router-events.tsapps/studio/compat/next/api.tsapps/studio/compat/next/compat/router.tsapps/studio/compat/next/dynamic.tsxapps/studio/compat/next/head.tsxapps/studio/compat/next/image.tsxapps/studio/compat/next/legacy/image.tsxapps/studio/compat/next/link.tsxapps/studio/compat/next/navigation.tsapps/studio/compat/next/router.tsapps/studio/compat/next/script.tsxapps/studio/compat/next/server.ts
🎭 Playwright Test ResultsDetails
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
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.
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.
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.
Braintrust eval report
|
… from #46424) (#47112) **Stack 3/6** of the TanStack Start migration (#46424). Stacked on **#47110** (S2) → review that first; this PR's diff is the app shell. > [!NOTE] > Thin route wrappers that render the existing pages-router page components through the compat shims (S2). Next is untouched — it builds `pages/` and ignores `routes/`. The app doesn't function end-to-end on TanStack until the API + project routes land (S4/S5) and the flag is flipped. ## What's in this PR - `routes/__root.tsx` — root layout + a `beforeLoad` that runs the shared redirect rules; `router.tsx`. - `routes/_auth/*` — sign-in/up, forgot/reset password, SSO/MFA/partner sign-in, CLI login, Stripe-projects login. - `routes/_app/*` — account (me/security/audit/tokens), `org/$slug/*` (general/billing/team/usage/…), support. - `routeTree.gen.ts` — **regenerated** by the tanstackStart vite plugin for exactly the routes in this PR (the migration branch's tree references all ~300 routes, so it can't be copied verbatim here). It's a generated artifact; the meaningful review surface is the route files. ## Verification On top of S1+S2: `studio` typecheck ✓, lint (0 errors) ✓. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Enhanced internal routing infrastructure to improve application performance and code organization. These behind-the-scenes updates ensure a more stable and maintainable foundation for the platform without affecting existing functionality or user experience. <!-- 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 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 Webfetchhandler.Verification
On top of S1:
studiotypecheck ✓, lint (0 errors) ✓. Next build is unaffected (nothing imports these under tsc).Summary by CodeRabbit
New Features
Tests