fix: preserve HTTP status codes during prerendering (#99078)
## Summary Set the correct HTTP status and redirect location when a prerendered page throws `notFound()`, `unauthorized()`, `forbidden()`, `redirect()`, or `permanentRedirect()` inside Suspense. Preserve the prerendered layout and Suspense fallback so the client can recover at the appropriate error boundary. Redirects take precedence over HTTP access fallbacks. Among access fallbacks, or among redirects, the first observed error wins. The HTML error callback and prerender recovery catch share this rule, so a later fatal not-found error cannot overwrite an already captured redirect. The catch still classifies its own error independently of the selected response. Request-time streaming behavior is unchanged. A dynamic not-found after `connection()` can still return 200. The custom error UI itself is not prerendered and remains a follow-up. Related: [NAR-435](https://linear.app/vercel/issue/NAR-435/set-status-code-on-prerendered-output-whenever-notfound-or-redirect). ## Verification - All 57 production Turbopack tests pass with Cache Components enabled and disabled, with `__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true`. This includes 44 ordered-error cases covering sibling Suspense boundaries and the outer recovery catch, status/location consistency, and preserved layout/fallback HTML. - Removing the precedence fix causes 22 regression cases to fail. - All 36 existing on-demand prerender recovery tests pass with Cache Components enabled: `NEXT_SKIP_ISOLATE=1 NEXT_TELEMETRY_DISABLED=1 __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true __NEXT_CACHE_COMPONENTS=true pnpm test-start-turbo test/e2e/app-dir/on-demand-prerender-error-boundary/on-demand-prerender-error-boundary.test.ts`. - Dev gate verified: all 57 tests are skipped. - Local tests used the installed SWC canary.38 binary with Next.js canary.42 and emitted a version mismatch warning. Deploy mode was not run locally. <!-- NEXT_JS_LLM --> --------- Co-authored-by:Jamiboy Mohammad <2085704+jamiboym@users.noreply.github.com>
Showing
Please
register
or
sign in
to comment