Moves every `pages/api/**` handler into its TanStack server route under
`routes/api/**` and deletes `pages/api/**`, part of the final pass of
the TanStack Start migration (FE-3106). Handlers move verbatim and still
run through `toWebHandler`, so auth (`apiWrapper`), response shapes and
headers are unchanged. Part 2 of the stack.
**Depends on:** #53199
**Changed:**
- `routes/api/**` – each route now holds its handler (formerly the
`pages/api` default export) as a local `nextHandler`/named function.
Next-only `config`/`maxDuration` exports are dropped: `vite.config.ts`
already sets the function `maxDuration`, and `toWebHandler` parses
bodies itself
- `routes/api/ai/docs.ts` – Web-native handler inlined, `NextRequest` →
`Request`
- `lib/api/apiHelpers.ts` – `getPgMetaRedirectUrl` moved here from the
old `tables` handler, which the other pg-meta routes imported it from
- `eslint.config.cjs`, `.github/CODEOWNERS` – `pages/api` paths →
`routes/api`
- `tests/routes/api/**`, `lib/api/{generate-v4,rate}.test.ts`,
`scripts/__tests__/server-source-maps.test.ts` – call the route's
registered handler with a Web `Request` (`tests/lib/server-route.ts`);
the MCP query-validation cases now run against the native route
**Removed:**
- `pages/api/**` (102 files), including the Next twins of the
already-native `routes/api/mcp/index.ts` and `functions/$slug/body.ts`
- unused `ProjectSettings` types and the `node-mocks-http` dev
dependency
Parity: every route registers the same methods its handler serves. The
exceptions are `check-cname`, `get-ip-address`, `get-utc-time`,
`get-s3-keys`, `get-deployment-commit`, `cli-release-version` and
`connect`: in Next they answered any method, and their routes register
`GET` only, as before this PR.
Addresses
[FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages).
## To test
- Load the table editor, SQL editor and Auth users on a self-hosted
build – `/api/platform/**` and `/api/v1/**` respond as before
- Use the Assistant and the docs search – `/api/ai/**` streams as before
- `GET /api/get-deployment-commit` – same JSON and `Cache-Control`
Ran typecheck, ESLint, lint ratchet, knip, Prettier, the TanStack build
and the full Studio vitest suite: all pass except
`lib/server/configcat.test.ts`, which also fails on `master` in an
environment with ConfigCat env vars set. Self-hosted E2E is CI-only.
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
## Context
_TLDR: Changes here speeds up unit tests on CI from ~14 minutes to ~3
minutes_ 😂
_TLDR 2: The file changes are solely only test files +
`studio-unit-tests.yml`_
We've currently got a lot of unit tests in the repository which while
great for coverage, hasn't been ideally written. There's a lot of
redundancy + overly specific tests that break easily, and our current
unit test takes about 15 minutes to run in the GHA per PR. Hence am
doing a audit clean up of all existing unit tests in the studio repo.
## Changes involved
- `.test.ts` files now run in `node`, `.test.tsx` in `jsdom`
- jsdom costs about 1s of setup per file. A `.ts` test that needs the
DOM opts in with `// @vitest-environment jsdom` (46 files do).
- Removed redundant and over-specific tests
- Duplicates are merged into `test.each`. Tests that only covered
libraries, existed for coverage, or asserted class names and snapshots
are deleted. 19 files are merged into a sibling or deleted.
- Fixed about 15 tests that couldn't fail
- Examples: unawaited assertions, fixtures equal to the default, and a
`semverGte` test calling `semverLte`.
- Sped up the slowest files
- Real sleeps are replaced with fake timers, `user.type` with paste, and
Radix option queries are scoped to the open listbox. For example,
`RestoringState` went from 18s to 0.3s and
`useTableEditorFiltersSort.navigation` from 20s to 3s.
- These ^ already shave down the unit tests time from 14 mins to 9 mins,
but am also sharding unit tests across 4 jobs to increase speed up
further which then shaves down time to 3 mins now
TanStack server maps now preserve original TypeScript locations through
both Nitro build stages. Sentry can upload those maps before final
server and public maps are removed; intermediate SSR maps remain
available for composition.
**Changed:**
- Enable Nitro server maps with original source content and compose
adjacent SSR maps through a build-only Vite loader scoped to the Nitro
environment.
- Keep intermediate maps until Nitro consumes them. Apply Sentry’s
bundler plugin to client and final server outputs, preventing
intermediate SSR IDs from overriding the final uploaded map ID. Remove
final server maps after eligible uploads; skipped or unauthenticated
uploads retain private maps.
- Preserve the existing Sentry release, project, credentials,
middleware, and separate Next configuration.
**Added:**
- Real two-stage Node and Vercel build regressions for original
TypeScript positions, runtime debug-ID matching against the installed
Sentry SDK, map cleanup timing, malformed maps, and loader boundaries.
## To test
- Build an actual TanStack preview with the existing Sentry upload
settings. Confirm client and final server uploads include maps,
intermediate SSR maps remain available for composition, final/public
maps are removed, and the deployed function remains within its size
limit.
- Inspect a public JavaScript asset's map URL; it should not expose a
source map.
- Build with uploads skipped or credentials absent; private server maps
should remain, with no public maps.
- Reload an existing project and navigate through general settings and
an existing Edge Function without editing or submitting anything.
- Before production rollout, confirm browser and server events resolve
to useful original source locations in the intended Sentry project.
Validation: 22 focused tests, Studio typecheck, scoped ESLint,
formatting, knip, full source lint ratchet, and both framework
production builds passed. Full-app artifact tracing resolves a compiled
handler to its original TypeScript line with exact source content. The
skipped-upload Vercel build contains zero public maps and no function
symlinks. Local TanStack browser checks passed for project/reload,
untouched general settings and support, and an existing function
editor/reload; a final retest after the runtime-ID fix passed with no
module or Sentry errors. A previously observed devtools
support-lifecycle warning remains unattributed. An explicit TanStack
preview of this commit reached READY: client and final Nitro uploads
succeeded, with no intermediate SSR upload. A shell-referenced
JavaScript asset returned 200 with immutable caching and its map URL
returned 404. Upload reports still contain unmapped files; original app
TypeScript mapping and runtime-ID association are established by build
artifacts/fixtures, while real event deobfuscation remains rollout QA.
Deployment acceptance confirms this preview fits its configured function
limits; exact deployed size and post-upload server contents were not
independently downloaded. No package patch, dependency, or new
environment variable is required.
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>