[FE-3106] (part 1) – ci(studio): build and test tanstack start only (#53199)

First part of the FE-3106 cleanup (final pass of the TanStack Start
migration): Studio now builds, runs and tests TanStack Start only.
Retiring the Next build first is what lets the follow-up PRs in this
stack delete `pages/**` files without breaking a still-built Next
runtime, the Next E2E shard or Next previews. Part 1 of the stack, based
on `master`.

**Changed:**
- `apps/studio/package.json` – `dev`/`build`/`start` run the Vite/Nitro
build directly (the former `*:tanstack` scripts)
- `apps/studio/vercel.ts` – always emits the TanStack Start config
(`framework: null`, redirects, headers); no `STUDIO_FRAMEWORK` gate, so
every Vercel project building Studio deploys the Nitro output
- `apps/studio/Dockerfile` – single TanStack `build` stage; the image no
longer defaults to Next
- `.github/workflows/studio-e2e-test.yml` – one E2E run (2 shards)
instead of a `next`/`tanstack` matrix; drops the `.next` cache step
- `.github/workflows/studio-docker-build.yml` – one image build
- `apps/studio/turbo.jsonc` – drops `STUDIO_FRAMEWORK` and the `.next`
outputs
- `apps/studio/AGENTS.md`, `apps/studio/TANSTACK_MIGRATION.md` –
describe the TanStack-only runtime

**Removed:**
- `dev:next`/`build:next`/`start:next` scripts, `scripts/dispatch.js`,
`scripts/lib/env.js`, the Turbopack cache `predev` script, and the root
`build:studio:docker:tanstack` script

Addresses
[FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages).

Before merging: branch protection lists `E2E tests (next, 1, 2)`/`(next,
2, 2)` and `E2E tests (tanstack, 1, 2)`/`(tanstack, 2, 2)` as required
checks. The jobs are now `E2E tests (1, 2)`/`(2, 2)`, so the required
checks need updating. Any Vercel project or self-hosted image still on
Next switches to TanStack Start with this PR.

## To test

- `pnpm dev:studio` without `STUDIO_FRAMEWORK` set – Vite dev server
starts on :8082
- `pnpm build --filter=studio` – Vite/Nitro build succeeds, no `.next`
output
- Vercel previews (`studio`, `studio-self-hosted`, `studio-staging`) –
build and serve the TanStack app
- `Studio Docker Build` and E2E checks – pass with the single TanStack
run

Ran `vercel.test.ts`, studio typecheck, knip, ESLint on changed files,
Prettier and the TanStack build locally. Docker and E2E are verified by
CI only.

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
This commit is contained in:
Alaister YoungandAlaister Young authored and GitHub committed 2026-11-11 06:04:46 +00:00
1 parent 6eb785a8a2
commit 200cc3f65d
15 files changed
+54 -306

No files matched your search

@@ -40,8 +40,3 @@ jobs:
- name: Build
if: steps.filter.outputs.studio == 'true'
run: docker build . -f apps/studio/Dockerfile --target production -t supabase-studio:local --build-arg NEXT_PUBLIC_STUDIO_AUTH_MODE=supabase --no-cache
# Reuses the shared stages (deps/dev) from the first build's layer
# cache; only the tanstack build/runtime stages run fresh.
- name: Build (tanstack)
if: steps.filter.outputs.studio == 'true'
run: docker build . -f apps/studio/Dockerfile --target production -t supabase-studio:local-tanstack --build-arg NEXT_PUBLIC_STUDIO_AUTH_MODE=supabase --build-arg STUDIO_FRAMEWORK=tanstack
+9 -34
View File
@@ -17,7 +17,6 @@ jobs:
strategy:
fail-fast: false
matrix:
framework: [next, tanstack]
shardIndex: [1, 2]
shardTotal: [2]
outputs:
@@ -28,11 +27,6 @@ jobs:
id-token: write
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
# Consumed by `apps/studio/scripts/dispatch.js` to pick which framework
# build/start scripts run. `next` keeps the existing pages-router flow;
# `tanstack` exercises the Vite/TanStack-Start migration in parallel
# so we catch regressions on either side per-PR.
STUDIO_FRAMEWORK: ${{ matrix.framework }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
@@ -88,20 +82,6 @@ jobs:
background: true
run: pnpm -C e2e/studio exec playwright install chromium --with-deps --only-shell
- name: Set up NextJS/Turbo cache
if: steps.filter.outputs.studio == 'true'
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
# See here for caching with `yarn`, `bun` or other package managers https://github.com/actions/cache/blob/main/examples.md or you can leverage caching with actions/setup-node https://github.com/actions/setup-node
path: |
apps/studio/.next/build
apps/studio/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('apps/studio/**/*.js', 'apps/studio/**/*.jsx', 'apps/studio/**/*.ts', 'apps/studio/**/*.tsx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('pnpm-lock.yaml') }}-
# Authenticate with AWS ECR to avoid rate limiting
- name: configure aws credentials
if: steps.filter.outputs.studio == 'true' && !github.event.pull_request.head.repo.fork
@@ -139,11 +119,10 @@ jobs:
# the API URL, fixed by e2e/studio/supabase/config.toml. So build
# against that URL and check it against the real value once supabase is up.
#
# `MODE=test` so the Vite build (TanStack) loads `.env.test` for env
# resolution; Next ignores it but reads `NODE_ENV=test` for the same
# purpose. Vite's `vite.config.ts` overrides the bundle NODE_ENV to
# 'production' regardless of input, mirroring Next's build behaviour
# so vitest-only constants (e.g. `API_URL`) don't bleed in here.
# `MODE=test` so the Vite build loads `.env.test` for env resolution.
# `vite.config.ts` overrides the bundle NODE_ENV to 'production'
# regardless of input, so vitest-only constants (e.g. `API_URL`)
# don't bleed in here.
run: |
echo '{"API_URL":"http://127.0.0.1:54321"}' > keys.json
node scripts/generateLocalEnv.js
@@ -181,7 +160,7 @@ jobs:
if: always() && steps.filter.outputs.studio == 'true'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: blob-report-${{ matrix.framework }}-${{ matrix.shardIndex }}
name: blob-report-${{ matrix.shardIndex }}
path: e2e/studio/blob-report
retention-days: 7
@@ -192,15 +171,11 @@ jobs:
exit 1
merge-reports:
name: 'E2E reports (${{ matrix.framework }})'
name: 'E2E reports'
# Merge reports after playwright-tests, even if some shards have failed
if: ${{ !cancelled() && needs.test.outputs.tests_ran == 'true' }}
needs: [test]
runs-on: blacksmith-4vcpu-ubuntu-2404
strategy:
fail-fast: false
matrix:
framework: [next, tanstack]
permissions:
contents: write
pull-requests: write
@@ -217,7 +192,7 @@ jobs:
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v 5.0.0
with:
path: e2e/studio/blob-report
pattern: blob-report-${{ matrix.framework }}-*
pattern: blob-report-*
merge-multiple: true
- name: Merge Playwright reports
@@ -225,7 +200,7 @@ jobs:
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: playwright-artifacts-${{ matrix.framework }}
name: playwright-artifacts
path: |
e2e/studio/playwright-report/
e2e/studio/test-results/
@@ -236,7 +211,7 @@ jobs:
uses: daun/playwright-report-comment@be9e270edd5ad86038604d3caa84a819a6ff6fed # v3.10.0
with:
report-file: e2e/studio/test-results/test-results.json
comment-title: '🎭 Playwright Test Results (${{ matrix.framework }})'
comment-title: '🎭 Playwright Test Results'
merge-results:
name: 'E2E results'
+5 -6
View File
@@ -1,6 +1,6 @@
# Supabase Studio
Next.js pages router + TanStack Start (mid-migration, see below), React 19. Dev server: `pnpm dev:studio` → http://localhost:8082.
TanStack Start + React 19 (final cleanup of the Next.js migration in progress, see below). Dev server: `pnpm dev:studio` → http://localhost:8082.
## Skills — load before working
@@ -22,12 +22,11 @@ Load the skills matching the task; stack them when a task spans areas:
## TanStack Start migration
Studio is migrating from the Next.js pages router (`pages/**`) to TanStack Start (`routes/**`). Both runtimes ship side-by-side; the `STUDIO_FRAMEWORK` env var selects which one `pnpm dev`/`build` runs (default: `next`, resolved in `scripts/dispatch.js`). Full route map and strategy: `TANSTACK_MIGRATION.md`.
Studio runs on TanStack Start (`routes/**`); `pnpm dev`/`build` no longer build Next.js. `pages/**` now only holds page bodies that some `routes/**` files still re-export because they haven't moved yet; the remaining FE-3106 PRs move them into their routes and delete `pages/**`. Route map: `TANSTACK_MIGRATION.md`.
- **Never delete a page file.** Most `routes/**` files are thin wrappers re-exporting the default export of their `pages/**` counterpart, so the Next file is load-bearing for both runtimes until the final cleanup pass.
- Pure page-body edits propagate to the route automatically. Mirror a change by hand into the corresponding `routes/**` file only when it touches what the route duplicates: `getLayout`/layout wrapping, page titles or other `staticData` (incl. `skip*Layout` flags), `withAuth`, or redirect paths.
- A new page under `pages/**` needs a matching route under `routes/**` plus a checklist entry in `TANSTACK_MIGRATION.md`.
- New code uses native TanStack APIs — no `next/router` or `next/link`. The `compat/next/` shims exist only for legacy re-exported pages.
- Don't add new files under `pages/**`. A new page is a `routes/**` file.
- Editing a page that's still under `pages/**` is fine: its route re-exports it. Layout wrapping, titles and other `staticData`, `withAuth` and redirects live in the route file, so change them there (`getLayout` is ignored).
- New code uses native TanStack APIs — no `next/router` or `next/link`. The `compat/next/` shims exist for older components that still import `next/*`.
- `routeTree.gen.ts` is generated by the Vite plugin — never hand-edit.
## Orientation
+9 -35
View File
@@ -1,22 +1,13 @@
# To be run in the root of the turbo monorepo
# NOTE: It's highly recommended to use the new builder, Buildkit. https://docs.docker.com/build/buildkit/
## USAGE:
# Build (Next): docker build . -f apps/studio/Dockerfile --target production -t studio:latest
# Build (TanStack): docker build . -f apps/studio/Dockerfile --target production -t studio:latest --build-arg STUDIO_FRAMEWORK=tanstack
# Build: docker build . -f apps/studio/Dockerfile --target production -t studio:latest
# Run: docker run -p 3000:3000 supabase/studio
# Deploy: docker push supabase/studio:latest
# Clean build:
# docker builder prune
# docker build . -f apps/studio/Dockerfile --target production -t studio:latest --no-cache
# Which framework's build ends up in the image. This is the same variable
# scripts/dispatch.js keys on for the dev/build/start scripts, so
# `--build-arg STUDIO_FRAMEWORK=tanstack` is the docker spelling of the
# switch used everywhere else. Framework selection happens at image build
# time (the two runtimes need different build outputs and dependency
# trees), not at container start.
ARG STUDIO_FRAMEWORK=next
FROM node:22-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
@@ -48,7 +39,8 @@ COPY --from=turbo /app/out/json ./
COPY --from=turbo /app/out/pnpm-lock.yaml ./
COPY ./patches/ ./patches
# No need to clean cache because production uses standalone build
# The production stage copies only the self-contained build output, so the
# install cache never reaches the final image.
RUN pnpm install --frozen-lockfile
# dev contains dependencies and source code not compiled
@@ -58,43 +50,25 @@ ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 8082
CMD ["pnpm", "dev:studio"]
# Compile Next.js
FROM dev AS build-next
RUN pnpm --filter studio exec next build
# Assemble the runtime tree at /srv in the layout the production stage
# serves from: Next's self-contained standalone output is the app root,
# with the static assets and public/ laid alongside it.
RUN mkdir -p /srv && \
cp -a apps/studio/.next/standalone/. /srv/ && \
mkdir -p /srv/apps/studio/.next && \
cp -a apps/studio/.next/static /srv/apps/studio/.next/static && \
cp -a apps/studio/public /srv/apps/studio/public
# Compile TanStack Start (Vite + Nitro)
FROM dev AS build-tanstack
RUN NODE_OPTIONS=--max-old-space-size=4096 pnpm --filter studio run build:tanstack
FROM dev AS build
RUN NODE_OPTIONS=--max-old-space-size=4096 pnpm --filter studio run build
# Assemble the runtime tree at /srv. Nitro's node-server output is
# self-contained (`.output/server` bundles the app with its traced
# dependencies, `.output/public` holds the client assets), so no node_modules
# install is needed. The server.js shim loads `.env` (container env vars win)
# and gives the production stage one CMD for both frameworks; package.json is
# copied so the shim runs as ESM.
# install is needed. The server.js shim loads `.env` (container env vars win);
# package.json is copied so the shim runs as ESM.
RUN mkdir -p /srv/apps/studio && \
cp -a apps/studio/.output /srv/apps/studio/.output && \
cp apps/studio/package.json apps/studio/.env /srv/apps/studio/ && \
printf "process.loadEnvFile(new URL('.env', import.meta.url))\nawait import('./.output/server/index.mjs')\n" > /srv/apps/studio/server.js
# Alias whichever framework build was selected so the production stage can
# COPY from a single stage name. BuildKit only builds the selected branch.
FROM build-${STUDIO_FRAMEWORK} AS build
# Copy only compiled code and dependencies
FROM base AS production
COPY --from=build /srv ./
# Both servers read PORT (the TanStack `start` script defaults it to 8082);
# pin it to the port the healthcheck and compose files expect.
# The server reads PORT (the `start` script defaults it to 8082); pin it to
# the port the healthcheck and compose files expect.
ENV PORT=3000
EXPOSE 3000
ENTRYPOINT ["docker-entrypoint.sh"]
+14 -22
View File
@@ -2,31 +2,23 @@
Temporary tracking doc. Delete once migration is done.
**Runtime model — Next.js and TanStack Start run side-by-side**
**Runtime model — TanStack Start only**
Throughout this migration both runtimes coexist in the same workspace:
FE-3106 retired the Next build (`build:next` / `dev:next`, `scripts/dispatch.js`,
the `STUDIO_FRAMEWORK` switch and the Next E2E shard). `pnpm dev`/`build`/`start`
run the Vite/TanStack build only, so nothing serves `pages/...` any more.
- The Next.js pages router (`pages/...`) and the TanStack route tree
(`routes/...`) ship **at the same time**. The Vite/TanStack build is
what we run today; the Next build (`build:next` / `dev:next` scripts
in `apps/studio/package.json`) stays alive as a fallback so we can
bisect regressions and ship either runtime if needed.
- **Do not delete any `apps/studio/pages/...` file during the per-route
migration.** Path A pages re-export their `pages/` default export, so
the Next file is load-bearing for both runtimes. Removing it breaks
the Next build and breaks the TanStack route too.
- Body-moves and `pages/...` deletion happen **only in the final
cleanup pass**, after every route is represented in `routes/...` and
we're ready to retire the Next runtime entirely. That's a separate,
deliberate phase — not something to fold into individual route PRs.
- Same rule for the Next compat shims (`apps/studio/compat/next/`):
they stay until the cleanup pass, regardless of how many routes have
moved.
- `pages/...` files are plain modules: Path A routes still re-export them until
the cleanup pass moves each body into its route file and deletes the page.
- The FE-3106 cleanup PRs delete `pages/...` area by area; deleting a page is
safe once its route no longer imports it.
- The Next compat shims (`apps/studio/compat/next/`) stay while components
outside `routes/...` still import `next/*`.
**PR guardrail — mirror page edits into their route**
Because both runtimes ship at once, any change to a `pages/...` file can
leave its `routes/...` mirror stale. A CodeRabbit `path_instructions`
While a route still re-exports its page, a change to the `pages/...` file can
leave its `routes/...` wrapper stale. A CodeRabbit `path_instructions`
rule (`.coderabbit.yaml`, scoped to `apps/studio/pages/**`) posts a
review reminder on every PR that touches a page, prompting the author to
check whether the corresponding route needs the same change. It's a
@@ -53,9 +45,9 @@ Once every page is represented in `routes/`, we do a second pass to properly mov
Other rules:
- New code uses native TanStack APIs directly (no `next/router`, no `next/link`). The Next compat shim stays in place for pages we re-export.
- New code uses native TanStack APIs directly (no `next/router`, no `next/link`). The Next compat shim stays in place for code that still imports `next/*`.
- `withAuth()` HOC → TanStack `beforeLoad` on the containing route/layout. Apply this at shared-layout level where possible.
- **Never** delete a `pages/...` file mid-migration — both runtimes need to keep working. Body-moves and Next-file deletions are reserved for the cleanup pass at the very end, after every entry in this checklist is `[x]`. See "Runtime model" above.
- Body moves and `pages/...` deletions happen in the FE-3106 cleanup PRs; mark each entry `[x] A→done` as its page is deleted.
- Not migrated via this list: `pages/api/**` (Next API routes — separate migration), `_app.tsx`, `_document.tsx`, `_error`, `pages/org/_/[[...routeSlug]].tsx`, `pages/project/_/[[...routeSlug]].tsx` (catch-alls — revisit at the end).
**Legend**
+2 -3
View File
@@ -9,9 +9,8 @@
* table editor route). The Vite dev server shims `process`, so the crash
* only surfaces in the production/test build.
*
* vite.config.ts aliases `@sentry/nextjs` to this module for the TanStack
* build only — app source keeps importing `@sentry/nextjs`, and the Next
* build (`build:next`) is untouched.
* vite.config.ts aliases `@sentry/nextjs` to this module; app source keeps
* importing `@sentry/nextjs`.
*
* `@sentry/nextjs` re-exports `@sentry/react` (same version, 10.x) and adds
* Next-specific helpers on top. Everything Studio uses at runtime —
+4 -10
View File
@@ -5,19 +5,13 @@
"type": "module",
"scripts": {
"preinstall": "npx only-allow pnpm",
"dev": "node scripts/dispatch.js dev",
"build": "node scripts/dispatch.js build",
"start": "node scripts/dispatch.js start",
"dev:next": "next dev -p ${STUDIO_PORT:-8082}",
"build:next": "next build",
"start:next": "next start -p 8082",
"dev:tanstack": "NODE_OPTIONS=--max-old-space-size=8192 vite dev --port ${STUDIO_PORT:-8082}",
"build:tanstack": "vite build --mode ${MODE:-production}",
"start:tanstack": "node --env-file-if-exists=.env --env-file-if-exists=.env.local --env-file-if-exists=.env.${MODE:-production} --env-file-if-exists=.env.${MODE:-production}.local .output/server/index.mjs",
"dev": "NODE_OPTIONS=--max-old-space-size=8192 vite dev --port ${STUDIO_PORT:-8082}",
"build": "vite build --mode ${MODE:-production}",
"start": "node --env-file-if-exists=.env --env-file-if-exists=.env.local --env-file-if-exists=.env.${MODE:-production} --env-file-if-exists=.env.${MODE:-production}.local .output/server/index.mjs",
"lint": "maybe-turbo eslint .",
"lint:type-checks": "eslint --no-inline-config --config eslint.type-checks.config.cjs .",
"lint:ratchet": "tsx node_modules/eslint-config-supabase/ratchet-eslint-rules.ts --rules-file scripts/ratchet-rules.json --rules-file node_modules/eslint-config-supabase/ratchet-rules.json",
"clean": "rimraf .next .turbo tsconfig.tsbuildinfo",
"clean": "rimraf .next .output .vercel/output .turbo tsconfig.tsbuildinfo",
"test": "vitest --run --coverage",
"test:watch": "vitest watch",
"test:ui": "vitest --ui",
@@ -1,22 +0,0 @@
import { existsSync, readdirSync, rmSync, statSync } from 'fs'
import { join } from 'path'
// Cleans up the Turbopack cache by removing files that haven't been modified in the last 3 days. This is to
// prevent the cache from growing indefinitely and consuming too much RAM.
const cutoff = Date.now() - 3 * 24 * 60 * 60 * 1000 // 3 days in milliseconds
function clean(d) {
if (!existsSync(d)) return
for (const entry of readdirSync(d, { withFileTypes: true })) {
const p = join(d, entry.name)
if (entry.isDirectory()) {
clean(p)
} else if (statSync(p).mtimeMs < cutoff) {
rmSync(p)
}
}
}
export function cleanTurbopackCache(studioRoot) {
clean(join(studioRoot, '.next/dev/cache/turbopack'))
}
-69
View File
@@ -1,69 +0,0 @@
#!/usr/bin/env node
// Dispatch a top-level npm script (dev/build/start) to either the next- or
// tanstack-flavoured variant based on STUDIO_FRAMEWORK. We parse the env files
// (via the shared scripts/lib/env.js parser) and pull out only
// STUDIO_FRAMEWORK — we deliberately don't load the whole file into the
// child's process.env, because vite and the start script do their own .env
// loading and would otherwise refuse to override the dispatcher-set values,
// including NEXT_PUBLIC_IS_PLATFORM which the e2e `.env.test` needs to flip to
// `false`.
//
// Usage: node scripts/dispatch.js <target>
// target ∈ { dev, build, start }
//
// Resolves to `pnpm run <target>:<framework>` where framework is `tanstack`
// when STUDIO_FRAMEWORK=tanstack (set in the shell env, `.env`, or
// `.env.local`), otherwise `next`.
import { spawn } from 'node:child_process'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { cleanTurbopackCache } from './clean-turbopack-cache.mjs'
import { readEnvFiles } from './lib/env.js'
const target = process.argv[2]
if (!target) {
console.error('dispatch.js: missing target (expected one of: dev, build, start)')
process.exit(2)
}
const studioRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
// Shell env wins, then `.env.local`, then `.env` — the same precedence
// vite and the start script use, so STUDIO_FRAMEWORK set in either file is
// picked up (not just `.env.local`).
const fileEnv = readEnvFiles(studioRoot, ['.env', '.env.local'])
const studioFramework = process.env.STUDIO_FRAMEWORK ?? fileEnv.STUDIO_FRAMEWORK
const framework = studioFramework === 'tanstack' ? 'tanstack' : 'next'
const script = `${target}:${framework}`
// Prune stale Turbopack dev cache before the dev server starts. This is a local side effect
// rather than a build step, so it lives here instead of in a `predev` hook or a turbo task.
if (target === 'dev') cleanTurbopackCache(studioRoot)
// Use async `spawn` rather than `spawnSync` — long-running dev servers
// (vite dev / next dev) wedge under `spawnSync` because Node holds the
// event loop and stdin doesn't flow through cleanly. The dev server says
// "ready" then exits ~1s later. `spawn` + manual forwarding keeps the
// child interactive and lets the parent exit cleanly when the child does.
const child = spawn('pnpm', ['run', script], {
stdio: 'inherit',
env: process.env,
})
const forwardSignal = (signal) => {
if (!child.killed) child.kill(signal)
}
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGQUIT']) {
process.on(signal, () => forwardSignal(signal))
}
child.on('exit', (code, signal) => {
if (signal) process.kill(process.pid, signal)
else process.exit(code ?? 1)
})
child.on('error', (err) => {
console.error('dispatch.js: failed to spawn child:', err)
process.exit(1)
})
-50
View File
@@ -1,50 +0,0 @@
// .env parsing for scripts/dispatch.js. We parse the small subset of the
// dotenv format we actually rely on — `KEY=value`, an optional `export`
// prefix, and surrounding single/double quotes — rather than taking on the
// `dotenv` dependency for one build script. Crucially, nothing here touches
// `process.env`: callers decide what to do with the parsed values, which is
// what lets dispatch.js read a single key without leaking the whole file into
// the child process.
import { readFileSync } from 'node:fs'
import path from 'node:path'
const ENV_LINE = /^\s*(?:export\s+)?([\w.-]+)\s*=\s*(.*?)\s*$/
// Parse the contents of a single env file into a plain key/value object.
export function parseEnv(content) {
const parsed = {}
for (const raw of content.split('\n')) {
const m = ENV_LINE.exec(raw)
if (!m) continue
let value = m[2]
if (
(value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))
) {
value = value.slice(1, -1)
}
parsed[m[1]] = value
}
return parsed
}
// Read a cascade of env files from `dir`, with later files overriding earlier
// ones — matching the precedence vite/Next use
// (`.env` < `.env.local` < `.env.<mode>` < `.env.<mode>.local`). A missing file
// is skipped, but any other read error (permissions, IO) is surfaced rather
// than silently dropping that file's values. Returns the merged key/value
// object; never mutates process.env.
export function readEnvFiles(dir, files) {
const parsed = {}
for (const file of files) {
let content
try {
content = readFileSync(path.join(dir, file), 'utf8')
} catch (err) {
if (err && typeof err === 'object' && err.code === 'ENOENT') continue
throw err
}
Object.assign(parsed, parseEnv(content))
}
return parsed
}
-6
View File
@@ -124,9 +124,6 @@
// Read by the Nitro server behind `pnpm start`. Declared so the turbo
// env lint rule passes even though turbo doesn't drive `start`.
"PORT",
// Gates the TanStack vs Next path in vercel.ts and
// scripts/dispatch.js (the dev/build/start dispatcher).
"STUDIO_FRAMEWORK",
// Vite's built-in `import.meta.env.SSR` flag (used in ConnectStepsSection
// to gate Vite-only `import.meta.glob`). Not a real process env var
// but turbo's `no-undeclared-env-vars` lint flags any `env.SSR` access.
@@ -142,9 +139,6 @@
"S3_PROTOCOL_ACCESS_KEY_SECRET",
],
"outputs": [
".next/**",
"!.next/cache/**",
"!.next/dev/**/*",
// TanStack Start via Nitro: node server and Vercel Build Output.
".output/**",
".vercel/output/**",
-15
View File
@@ -19,7 +19,6 @@ afterEach(() => {
describe.each(['', '/dashboard'])('Vercel headers with base path "%s"', (basePath) => {
it('leaves only exact deployment metadata paths to the handler cache policy', async () => {
vi.stubEnv('STUDIO_FRAMEWORK', 'tanstack')
vi.stubEnv('NEXT_PUBLIC_BASE_PATH', basePath)
const { config } = await import('./vercel')
const compiled = getTransformedRoutes({ headers: config.headers })
@@ -60,18 +59,6 @@ describe.each(['', '/dashboard'])('Vercel headers with base path "%s"', (basePat
expect(securityRule).toBeDefined()
}
})
it.each([undefined, 'next'])(
'leaves the Next.js Vercel config empty for framework %s',
async (framework) => {
vi.stubEnv('STUDIO_FRAMEWORK', framework)
vi.stubEnv('NEXT_PUBLIC_BASE_PATH', basePath)
const { config, default: defaultConfig } = await import('./vercel')
expect(config).toEqual({})
expect(defaultConfig).toBe(config)
}
)
})
describe.each(['', '/dashboard'])('TanStack content types with base path "%s"', (basePath) => {
@@ -79,7 +66,6 @@ describe.each(['', '/dashboard'])('TanStack content types with base path "%s"',
beforeEach(async () => {
vi.resetModules()
vi.stubEnv('STUDIO_FRAMEWORK', 'tanstack')
vi.stubEnv('NEXT_PUBLIC_BASE_PATH', basePath)
const { config } = await import('./vercel')
const result = getTransformedRoutes({ headers: config.headers })
@@ -145,7 +131,6 @@ describe.each(['', '/dashboard'])(
beforeEach(async () => {
vi.resetModules()
vi.stubEnv('STUDIO_FRAMEWORK', 'tanstack')
vi.stubEnv('NEXT_PUBLIC_BASE_PATH', basePath)
vi.stubEnv('NEXT_PUBLIC_IS_PLATFORM', 'true')
vi.stubEnv('MAINTENANCE_MODE', 'true')
+2 -16
View File
@@ -9,17 +9,6 @@ import {
} from './redirects.shared'
import { getSecurityHeaders } from './security-headers'
// STUDIO_FRAMEWORK gates the TanStack Start deploy. When the env var is
// unset (the default — used by the Next.js prod deploy) this file returns
// an empty `VercelConfig` so Vercel honours the dashboard-configured
// Next.js preset untouched. Vercel reads `vercel.ts` regardless of the
// framework preset (per vercel.com/docs/project-configuration —
// `vercel.ts`'s `framework` field overrides the dashboard preset), so a
// no-op early return is the only way to keep `framework: null` and the
// headers below from clobbering the Next build. Set
// `STUDIO_FRAMEWORK=tanstack` on the TanStack Vercel project to opt in.
const isTanstack = process.env.STUDIO_FRAMEWORK === 'tanstack'
// Routing lives in Nitro's Build Output config (`.vercel/output/config.json`,
// shaped by scripts/vercel-spa-routes.ts). Vercel applies this file's
// `redirects`/`headers` ahead of it, which is also why no `rewrites` belong
@@ -87,7 +76,7 @@ function buildRedirects(): Redirect[] {
]
}
function buildTanstackConfig(): VercelConfig {
function buildConfig(): VercelConfig {
// Vercel's Flags Explorer probes `/.well-known/vercel/flags` and expects
// JSON. next.config.ts proxies it to supabase.com's endpoint and forces
// `content-type: application/json`; mirror that here. It lives at the domain
@@ -112,10 +101,7 @@ function buildTanstackConfig(): VercelConfig {
}
}
// Empty config = no overrides; Vercel falls back to the dashboard preset.
const passthrough: VercelConfig = {}
export const config: VercelConfig = isTanstack ? buildTanstackConfig() : passthrough
export const config: VercelConfig = buildConfig()
// Belt-and-braces: local @vercel/config CLI reads module.default, but the
// docs claim Vercel's platform looks for a named `config` export. Export
+9 -12
View File
@@ -236,8 +236,7 @@ function umdAmdShortCircuit(): Plugin {
// a function"). Deep imports (`lodash/isEqual`) fail harder: their plain-CJS
// `require` throws "require is not defined". lodash-es is the same version as
// real ESM, so both import styles just work. Client bundles are untouched —
// resolution is gated on `options.ssr`, and the Next build doesn't read this
// config.
// resolution is gated on `options.ssr`.
function ssrLodashEs(): Plugin {
return {
name: 'studio-ssr-lodash-es',
@@ -592,9 +591,8 @@ export default defineConfig(({ command, mode }) => {
server: {
port: 3000,
watch: {
// Next's build output, left behind when switching from
// STUDIO_FRAMEWORK=next, includes a full node_modules copy under
// `.next/standalone`.
// A leftover `.next/` from the retired Next build includes a full
// node_modules copy under `.next/standalone`.
ignored: ['**/.next/**'],
},
},
@@ -625,8 +623,8 @@ export default defineConfig(({ command, mode }) => {
// because the dev pipeline shims `process`. Point the bare import
// at a shim that re-exports `@sentry/react` (same 10.x version —
// it's what `@sentry/nextjs` wraps on the client) plus explicit
// stand-ins for the Next-only APIs. Next build (`build:next`)
// doesn't read this config and keeps the real package.
// stand-ins for the Next-only APIs. App source still imports
// `@sentry/nextjs`.
{
find: /^@sentry\/nextjs$/,
replacement: path.resolve(rootDir, 'compat/sentry-nextjs.ts'),
@@ -751,11 +749,10 @@ export default defineConfig(({ command, mode }) => {
},
},
css: {
// Disable PostCSS auto-discovery. Studio's postcss.config.cjs is kept
// for the Next build (`build:next`) and uses `@tailwindcss/postcss`,
// but under Vite we let `@tailwindcss/vite` (added below) handle
// Tailwind v4 directives directly. Running both plugins on the same
// CSS would double-process Tailwind output.
// Disable PostCSS auto-discovery: studio's postcss.config.cjs uses
// `@tailwindcss/postcss`, but `@tailwindcss/vite` (added below)
// handles Tailwind v4 directives directly. Running both plugins on the
// same CSS would double-process Tailwind output.
postcss: { plugins: [] },
},
ssr: {
-1
View File
@@ -10,7 +10,6 @@
"build": "turbo run build",
"build:studio": "turbo run build --filter=studio",
"build:studio:docker": "docker build . -f apps/studio/Dockerfile --target production -t supabase-studio:local --build-arg NEXT_PUBLIC_STUDIO_AUTH_MODE=supabase --no-cache",
"build:studio:docker:tanstack": "docker build . -f apps/studio/Dockerfile --target production -t supabase-studio:local-tanstack --build-arg NEXT_PUBLIC_STUDIO_AUTH_MODE=supabase --build-arg STUDIO_FRAMEWORK=tanstack --no-cache",
"build:design-system": "turbo run build --filter=design-system",
"build:docs": "turbo run build --filter=docs",
"build:kb": "turbo run build --filter=kb",