feat(adapter): declare Next.js 16.5's method-based prerender bypass

SO
3d ago
+302-27

Summary

Declares Next.js 16.5's supportsPrerenderMethodBypass through the new getCapabilities hook of the Adapter API. Stacked on #579 (its base is that pull request's branch).

The build asks for capabilities once, synchronously, after modifyConfig (vercel/next.js#101911, build/adapter/build-complete.ts). With this one, an App Router page's prerender is bypassed on { type: 'method', value: 'POST' } instead of on the next-action header plus a multipart content type. Route handler prerenders keep the header pair, and releases before 16.5 never call the hook.

Why the method condition is left out of the bundle

Nothing this SDK deploys serves a prerender to a request of any method but GET or HEAD:

  • The edge hands every other method to the Function before it looks a route up (routeOtherMethod → classifyByMethod).
  • The runtime, on either target, hands it to the route's handler (serveResolved → serveWithBody).

So a condition on POST never decides an answer anywhere bypassFor is evaluated, and carriedBypassFor drops it. Carrying it would widen RouteHas with a type that older hosts and edges refuse, for no behaviour.

A method condition on GET or HEAD would mean "bypass the prerender for the very requests it is served to". Nothing here can judge that, so the build refuses it. Next.js 16.5 only writes POST.

Effect

  • Ordinary navigations: the edge judges two header conditions fewer per request (bypassForHolds).
  • Pages without PPR: their prerenders carry no bypassFor at all.
  • A read carrying next-action or a multipart body: it is now served the prerender, which is what Next.js does once it writes the method.
    • The edge still hands a GET with next-action to the Function (classifyByRouterHeaders), and the Function serves the stored prerender.
    • A multipart GET is served the shell at the edge.
  • A POST of any kind (action, form, text/plain) still invokes the handler; tests cover this.

Docs

packages/adapter/README.md states the invariant, lists bypassFor as read by the edge and the runtime (it was listed as merely recorded), and adds a "Capabilities declared to Next.js" section. The bot capability comes in a separate pull request.

Verification

  • adapter: collect.test.ts and adapter.test.ts.
  • core: classify.test.ts (POST/PUT/PATCH/DELETE are never a document; a multipart GET or HEAD is).
  • runtime: action-postponed.test.ts.
  • Result: 200 tests pass.
  • tsc for core, adapter and runtime, oxfmt and eslint on the touched files: clean.
  • Upstream deploy suite to watch on the next run: test/e2e/app-dir/prerender-methods.

Devin Review


Summary by cubic

Declares Next.js 16.5's supportsPrerenderMethodBypass capability through the new getCapabilities adapter hook, so an App Router page's prerender is bypassed on POST instead of a next-action header plus multipart content type. Route handler prerenders keep the header conditions, and releases before 16.5 never call the hook.

The method condition stays out of the bundle: no prerender is served to a request of anything but GET and HEAD on either target, so a POST condition never decides an answer, and carrying it would widen the schema for no behavior. A condition on GET or HEAD would bypass the prerender for every request it serves and is refused.

Effect

  • Ordinary navigations judge two fewer header conditions per request.
  • Pages without PPR carry no bypassFor at all.
  • A read carrying a next-action header or multipart body is now served the prerender, matching Next.js 16.5 behavior.
  • POSTs of any kind still invoke the page handler.

Summary by CodeRabbit

  • New Features
    • Added support for method-based prerender bypass behavior. Non-read requests are handled by the page rather than served a prerender; reads may use the prerender unless their headers or content type match a bypass condition.
  • Documentation
    • Clarified how prerender bypass conditions are evaluated and documented which method-based conditions are supported. Also explained when a build may be refused and how older readers handle unsupported conditions.