Generic page adapter (RSC mode)
Next pages are async server components with'use client' islands. Start’s RSC
environment (@tanstack/react-start RSC mode with @vitejs/plugin-rsc) runs
that code with the same boundaries Next enforces, so retained page source
renders unchanged.
Per request, a Start server function in the app (generated
src/start-bridge/page-route.tsx) calls resolveBridgePage from
start/page-render:
- Resolve the location the app sees (
start/page-location): on SSR the request the handler forwarded afterproxy.ts, so rewrites apply while the browser keeps its URL; on client navigation the app proxy runs for the target, so the same URL renders the same page, a proxy redirect becomes a Start redirect and any other terminal response reloads the document. Match that app-relative path (mount stripped; a leading locale segment addresses a manifest with a stripped[locale]) against the generated page manifest. A localized page for the stripped path wins over a dynamic segment that would capture the locale (/enis the landing page, not workspaceen); a page whose first segment is literally the locale still wins. No match answers 404. - Load the page and its layout/template chain from the generated
page-modules.bridge.gen.ts(lazy imports keyed by the manifestfile). - Pass Next’s props:
paramsandsearchParamsas Promises; repeated query keys become arrays. A stripped[locale]segment resolves from the middlewarex-next-intl-localeheader, thenNEXT_LOCALE, then the default. - Merge
metadata/generateMetadataandviewportlike Next (shallow merge, nearesttitle.template) and convert them tohead()data. - Lift the root layout’s
<html>/<body>attributes into the Start shell (createBridgeRootRoute). Server-component wrappers and the RSC CSS fragment around the root layout are expanded first; client references are never called. - Await async pages and layouts before streaming, so
notFound()andredirect()in their bodies answer 404 and redirect. Sync server components stay elements because they may call hooks. - Return the tree through
renderServerComponent; the catch-all and index routes render it, on SSR and on client navigation alike.
Route handlers run in the rsc environment
plugin-rsc rejectsserver-only in every environment except rsc, and the
Worker entry is bundled in ssr. The generated vite.config.mts registers the
API registry as the bridge-api rsc entry (rscEntries), and
cloudflare/worker.ts loads it with
import.meta.viteRsc.loadModule('rsc', 'bridge-api') before building the
handler. Route modules (and the server-only packages they import) are
compiled once, in rsc; the request store is global, so next/headers,
cookies and the mount see the same request. Never alias or disable plugin-rsc’s
import validation to make a build pass.
redirect() from next/navigation keeps an absolute URL absolute, as in
Next. Start’s router reduces a same-origin absolute href to its path, and on
the apex Web’s https://tuturuuu.com/login is same-origin with
tuturuuu.com/<app>, so the bridge marks the target for its response
finalization (which otherwise adds the mount) and sets reloadDocument for
client navigation. Without it, a mounted app’s login redirect loops into its
own /<app>/login.
Fonts from next/font resolve to inert objects; load font CSS through the app
stylesheet. A page that needs Next behaviour the adapter lacks (parallel or
intercepting routes) stays a hand-written page via owned/ignored in
start-bridge.routes.json.
Converting an app
--apply writes the same change set and installs the
pinned toolchain through bun add --exact in the app workspace; dependencies
are never edited into package.json by hand. The toolchain includes the
repository’s exact @cloudflare/workers-types pin, which the native binding
type check resolves from the app. The app’s .gitignore gains .void/ and
.void-wrangler.jsonc (local vp build output) when missing, appended after
its own lines. Re-running an applied app, including one
that already added a pin by hand, is a no-op. Every owned file carries a “Generated by the start-bridge codemod”
marker; an unmarked hand-written file is a conflict that blocks --apply
unless --adopt is passed. Codegen errors (an unregistered route.*/page.*),
a missing src/proxy.ts and, with --hold, a missing Vercel publisher also
block. Owned
files and the app’s JSON edits are formatted with the repository’s Oxc.
The codemod writes or edits:
start-bridge.routes.json(hand-maintainedowned/ignoredentries win on re-runs) and the bridge codegen registries, pluspage-modules.bridge.gen.tsandpublic-assets.bridge.gen.ts.vite.config.mts(preset in RSC mode),void.config.ts(the heldtuturuuu-<app>-vite-stagingWorker withTUTURUUU_NOINDEX=1and thenodejs_compatandglobal_fetch_strictly_publicflags; the latter sends same-zone self-fetches such as app-baseappUrl(path, request.url)to the Worker instead of the zone origin, the retained Vercel app),cloudflare/worker.ts(mounts:<app>.tuturuuu.comroot and thetuturuuu.com/<app>mount),tsconfig.cloudflare.json.src/start.ts(bridgeServerFnFetch),src/router.tsx(routerBasepath(),ssr: { nonce: requestNonce() }), the root/index/catch-all routes androuteTree.gen.ts. The Worker does not enforcecspby default: each app addscreateBridgeHandler({ csp })with a policy that fits its scripts before it mounts on the apex.- Package scripts
build:cloudflare,dev:cloudflare,preview:cloudflare(--configLoader runner),routes:checkandtype-check:cloudflare.buildstaysnext build, so the current Vercel deployment is unchanged. .env.examplemoves toenv.example: Void accepts only.env.- The
.oxfmtrc.jsonand.oxlintrc.jsonoverride that keeps every generatedrouteTree.gen.tsout of Oxc (formatter, linter and assist off), once for the repository. TanStack’s generator rewrites the file in its own format on each build, andbun check:changedpasses changed files to Oxc explicitly. - With
--holdonly, the held record:tuturuuu.ci.tsproductionPublicationPolicy, the protected surface inscripts/ci/production-publication-policy.tsand its regression’s app list, and theproduction-policygate invercel-production-<app>.yaml(as for Shortener). tsconfig.jsonexcludes the Start-only sources, so the existing Nexttype-checkis unchanged;type-check:cloudflarechecks them againsttsconfig.cloudflare.json.
Worker options
start-bridge.config.ts at the app root is app-owned: the codemod creates
it once (with the shared response policy below) and never updates or replaces it. The
generated cloudflare/worker.ts passes its options on, so an app changes
Worker behaviour without editing generated files:
API paths the app owns but forwards (Storefront’s Inventory APIs) are listed
client-safely in
start-bridge.routes.json as
"api": { "forwarded": ["/api/v1/inventory/[...path]"] }. The codegen merges
them into appApiPatterns, so the shared app-base resolver mounts them like
local routes, and the Worker, finding no local handler, forwards them through
apiOrigin. start-bridge.config.ts holds server code and is never imported
by the browser. The codemod and the runtime test load it with Node’s type
stripping, so keep its imports strippable (packages, or relative paths with
their .ts extension).
Response policy
Every app uses one tested policy instead of hand-rolledwrapResponse code,
which in four separate reviews kept repeating the same three bugs:
- caching set only as a default, so a handler’s
public, max-agesurvived; - an asset exemption that ignored the method, so
POST /assets/xescaped; - an existing CSP passed through without
frame-ancestors.
- Every response gets:
X-Robots-Tagfromseo.appRobotsreads the app’sseo-policy.jsonentry, which the codemod emits into the generated Worker (no runtime JSON). A response is left indexable only on the public allowlist on the canonical origin, outside reserved paths (api,login,dashboard,embed, …, in any letter case, as Next’s header sources match). Each path segment is decoded once before both checks, so/%61uthis/auth, and a malformed escape, an encoded/or\, or a double encoding stays private. Staging deployments (TUTURUUU_NOINDEX=1) are never indexable either. Everything else getsPRIVATE_ROBOTS_HEADER. An upstreamnoindexis never overridden;X-Content-Type-Options: nosniffandReferrer-Policy: strict-origin-when-cross-origin;- outside framable paths,
X-Frame-Options: DENY, andframe-ancestors 'none'in every CSP policy. An existingframe-ancestorsis replaced in any letter case, each comma-separated or repeated header policy is covered, and a response without a CSP getscsp(defaultframe-ancestors 'none').
- Caching: only
GET/HEADrequests for/assets/*or the app’s public files keep their own caching, unless they answer HTML. Every other response is set, not defaulted, toCache-Control: private, no-store, and gainsVary: Cookie. - Framable paths: the platform list (
@tuturuuu/utils/framable-paths, Web’s uploaded WebGL builds at/api/v1/workspaces/*/external-projects/assets/*/webgl), the app’sframablePathsand the policy’s ownframable. These keep the upstream CSP byte-for-byte, or its absence, and any upstreamX-Frame-Options(DENY/SAMEORIGIN) is removed. Web’ssandbox allow-scripts ...policy must reach the browser, or uploaded scripts run unsandboxed on the app origin. The handlercspskips the platform list and app-configframablePaths. The policy-onlyframableoption leaves the CSP it receives unchanged and does not bypass the handler; use app-configframablePathswhen the app setscsp. Matching is case-sensitive, unlike Next’s headersourcematching; that’s harmless because central’s routes are case-sensitive. One stateless matcher is shared by the handler and the policy:g/ypatterns are cloned without those flags, solastIndexnever changes a result. - Failures: a throw in the proxy, an endpoint, Start or the route load answers the bridge’s generic
500 Internal Server Error. The details go only toconsole.error, and the response still goes throughwrapResponse, so it gets no-store, robots and framing headers too. Hand-rolled wrappers that apps keep until they migrate also receive this generic 500, where a handler throw used to escape uncaught. They still run, and still see no error details. - Paths: framable and asset paths are matched app-relative, so on the
tuturuuu.com/<app>mount the base is stripped first. WebSocket upgrades (101) pass through untouched.
wrapResponse (Finance, Tasks, Track,
Storefront):
- Replace the function with
createRootResponsePolicy({ seo }). Put shared framing exceptions in app-configframablePaths, as above. Keep the app’s robots value asseo, for example'noindex, nofollow, nosnippet'. - Drop any import of
./src/start-bridge/public-assets.bridge.gen. The Worker now passespublicAssets, and an extensionless relative import cannot be loaded by the codemod or the runtime test, which read the config with Node’s type stripping. - Keep
csp(the nonce policy) as it is. The response policy addsframe-ancestors 'none'to it. - Re-run the codemod for the app, so its
cloudflare/worker.tspassesmountsandpublicAssets, then runbun check:changed.
Route handlers load lazily
The generated API registry (api.lazy) imports each route on its first
request (lazyRouteModule), with the route’s HTTP methods read statically
from its source so OPTIONS and 405 need no import. One route’s
dependencies (for example a Node-only SDK chain) therefore cannot fail the
Worker at startup; a route that re-exports with export * stays eager. In
the rsc build, CommonJS require() of Node built-ins becomes an ESM import
served by nodejs_compat, and .wasm/.bin imports become Wrangler
CompiledWasm/Data modules (as next/og’s Workers port needs). An app whose
Worker code runs in native SSR (rsc: { enabled: false }, as Calendar does)
opts its ssr environment into the same conversion by adding
startBridgeNodeBuiltinsPlugin() from @tuturuuu/start-bridge/vite/rsc to its
Vite plugins. Generated apps get it in vite.config.mts by default, before
voidPlugin(): their SSR bundles CommonJS too (Forms: sanitize-html, then
postcss’s require('path')). This is the same conversion the rsc environment
always applies, so a built-in workerd lacks fails when the chunk loads, which
the runtime gate exercises, rather than when the code runs. A route that
needs a Node API workerd does not provide still fails when it is hit; serve it
from Web (centralFirst) or port it.
Native CI
When the repository has the reusable.github/workflows/native-start-app.yaml
(#6753), the codemod also writes the app’s qualification CI, modelled on
Shortener:
.github/workflows/<app>-cloudflare.yaml: a thinworkflow_callcaller with path filters for the app, its transitive workspace dependencies, the template and the shared native CI scripts, and Shortener’s inputs. An app without atestscript runs its Vitest suite with--passWithNoTests. Registered intuturuuu.ci.ts.scripts/ci/<app>-native-artifact.py: the app’s Worker identity and public files overscripts/ci/apps-native-artifact.py.cloudflare/native-built-worker.runtime.mjs(test:runtime, run withnode --testafter the build; not a*.test.*file, so source test runs never pick it up): a generic emitted-Worker smoke run on the sealed artifact, with all egress denied: Worker identity, public-file parity, build identity when the app has/api/build-info(read anonymously, as production smoke does: an app whose proxy guards API routes must admit exactGET/HEAD /api/build-info), the page outcomes the app declares, no server error on an unknown path, and the response policy (no-store,X-Robots-Tag,X-Frame-Options: DENYandframe-ancestors 'none') on real responses, after checking their status and content: a page rendering 200 HTML (by default the firstruntimepath expecting 200), a 200 JSON API response (/api/build-info) and a 404 HTML page (/__native-smoke-missing__).runtimeProbesinstart-bridge.routes.jsonoverrides a probe’s path, or skips it with{ "skip": "<reason>" }. A skipped page or 404 probe must also name the app’s own runtime test that covers it, as"fixture": "cloudflare/<name>.runtime.mjs". For example, an auth-only app whose/redirects to login names its isolated-auth fixture. The fixture must be a distinct app-owned file thattest:runtime’scloudflare/*.runtime.mjsglob selects: never the generated gate itself, and never a dotfile, which the glob skips. The codemod and the gate both check this and that the fixture exists, and at least one probe must always run. A probe the codemod can neither default nor find declared, or a set that skips every probe, is a codemod problem. The test reads the Worker’s effective mounts (the generated defaults plusmountsin the app-ownedstart-bridge.config.ts, loaded with Node’s type stripping, so keep that file’s imports strippable) and probes with rawHostheaders: every configured root host serves/. A mounted app serves every declared page ontuturuuu.com/<app>. A root-only app (notuturuuu.cominmountHosts) must setunknownHost: 'reject', and the bridge must reject its apex paths and an unknown host with its own 404 before any app code runs, with no egress. Page outcomes come fromruntimeinstart-bridge.routes.json(default{ "/": 200 }): a record that must declare/, mapping app-relative paths to an exact status or{ "redirect": "<path or absolute URL>" }. A path redirect must stay on the requested origin and, on the apex, keep the/<app>mount, so a login redirect, a cross-origin hop or a jump to another app never passes. The codemod rejects empty, array or root-less maps, andscripts/start-bridge-codemod/runtime-outcome.mjsholds the shared checks. App-specific acceptance goes in furthercloudflare/*.runtime.mjsfiles, whichtest:runtime(node --test cloudflare/*.runtime.mjs) runs with it.
Signed-in root browser gate
scripts/ci/native-root-browser.mjs checks what the generated runtime test
cannot reach: signed-in SSR and client hydration in a real browser. It runs on
a build host with Chromium against the app’s restored, sealed artifact:
- Verifies the artifact against the receipt, starts it in local workerd at the app’s root host, and checks that build-info names the exact source.
- Signs a disposable app session with a random coordination secret.
- Answers every Supabase and Web request in-process: the fixture user, the
profile’s rows and Web responses, empty reads, and 401 for any other Web
API read. A request to the app’s own root host goes back to the Worker
under test, as a same-zone fetch does in production under
global_fetch_strictly_public. A self-fetch loop (more than 8 nested or 200 total) is stopped with508and fails the run. Any other Worker or browser request fails the run, and an SSR failure lists it. - For each locale, follows the signed-in SSR redirects. They must stay on the
root host and end on a
200page with<html lang>, emitted assets andprivate, no-store. Chromium then loads the same path and must hydrate. - Fails on page errors or failed
/assets/*, and re-verifies the artifact at the end.
apps/<app>/cloudflare/root-browser.profile.mjs
(a default-export object, no imports):
Regressions for the profile, session, egress, self-fetch and SSR rules, and a
check that every
apps/*/cloudflare/root-browser.profile.mjs is valid, run
with node --test scripts/ci/native-root-browser.test.mjs.
Generator inputs
The codemod reads app-specific behaviour from the app’s existing configuration, so apps regenerate instead of forking generated files:
The preset renders
@tuturuuu/vercel’s Analytics and Speed Insights as
nothing, because Workers serve no /_vercel/* scripts; an app with an explicit
shims list opts in with inertVercel: true.
Each environment bundle (browser, SSR, rsc) carries its own internal-api
module, so the registration is imported by src/router.tsx, the page route
and the rsc API entry (src/start-bridge/api-entry.ts).
Coverage report
The report classifies each page through its layouts and local import graph. A page is generic unless it reaches an unshimmed framework specifier or a parallel/intercepting segment. The shim list follows the bridge preset;'use server' modules and next/og are features, not blockers.
Verification
Codemod regressions run withnode scripts/start-bridge-codemod/<file>.test.mjs
on disposable fixture repositories; edits to repository files are tested
against the real anchors. Each converted app still needs exact-commit CI:
unit, types, lint, the real vp build, the sealed artifact and the
emitted-runtime and browser acceptance.