next.js
5c74a5f8 - [Experiment] Serve pages on the native RSC runtime via the adapter

Commit
15 hours ago
[Experiment] Serve pages on the native RSC runtime via the adapter A page with `experimental_nativeRscRuntime = true` is now served end to end, page → React → HTML, under `next start` and on Vercel through the deployment adapter, without going through base-server, and it no longer fails to build with "isn't implemented yet". Only one shape of page works, a page directly inside the root layout, and it's still scaffolding: it proves the wiring. The runtime's actual behavior is what the experiment builds next. The native RSC runtime is a highly experimental runtime for rendering React Server Components on the server; nothing changes for client components or in the browser. The entry exports `handler(req, res, ctx)`, with the signature every Node entry template has under the deployment adapter contract, so both hosts call it the same way: Vercel's launcher directly, and router-server under `next start`, which loads the matched page's entry and hands it the request. Nothing reads `ctx` yet. `next build` records the page as on the native RSC runtime in the functions config manifest, from the same static info that carries `runtime`, and the filesystem checker gives these pages their own `RouteKind` and route definition, as Go route handlers have, so router-server dispatches on the route's kind. Only the matched case goes to the native RSC runtime; not-found and error renders stay on App Router for now. A Vercel build without the adapter is a config error when the flag is on: `@vercel/next`'s other path serves pages through next-server's minimal mode, which these pages never reach. The bridge owns HTTP. It serves any host of the adapter contract, and it's precompiled like the renderer, in `prod` and `dev` bundles that the entry selects the same way. It answers methods other than GET and HEAD with a 405 and `Allow: GET, HEAD`, so a POST or a Server Action never renders the page. Otherwise it calls the renderer interface, waits for the outcome, writes 200 with HTML or a 500, and streams the body. Every response gets the `Cache-Control` App Router gives dynamic pages, from the same helper, and the headers the bridge writes replace any that the config or middleware set, as on App Router. Node's side of it lives in `#engine-http`, a new engine fork set that only the bridge imports, so the renderer never sees HTTP. The Node fork uses App Router's `createAbortController` and `pipeToNodeResponse`, so a client that goes away is handled the same way as on App Router and isn't an error. The entry composes the page's renderer from the RSC and SSR bundles, so the bridge sees only the renderer interface. The bridge's imports of App Router's helpers are typed through `paths` entries in `tsconfig.json`, not `declare module` in `$$compiled.internal.d.ts`, because a `next/dist/...` specifier resolves to the emitted declaration file, which TypeScript then refuses to overwrite (TS5055). These are left out of the first phase on purpose. File structure and segment exports the runtime doesn't support are build errors, but some request-time APIs aren't caught at build time, and fail when the page renders for now: `cookies()`, `headers()`, and `connection()` throw, with no request store to read; `notFound()` and `redirect()` are reported as errors and answered with a 500, because the renderer replaces their digests; `params` and `searchParams` aren't passed to the page; and `use cache` isn't supported. RSC requests get HTML: Vercel rewrites them to the `.rsc` path, which runs the same entry, and the client router falls back to a full page load. Direct dispatch also skips what next-server does for App Router pages under `next start`, such as compression. Skipping base-server is the point of direct dispatch, so that isn't a regression; what the runtime needs from it comes back in later steps. The e2e suite serves the page under `next start` and in deploy mode with the adapter: an async page renders, with the dynamic `Cache-Control`; a POST is a 405; a page that throws is a 500 with each render's error reported once; and a path with no page stays a 404 on App Router. Under `next start` it also checks that the page wasn't prerendered and that its `Content-Type` replaces one the config sets. Under `next dev` it checks the build error. The config unit test covers the Vercel check.
Author
Committer
Parents
Loading