Repository navigation
Keep 4xx status when there is no /_error page in App Router-only builds - #101188
Open
Mahdi-Hasan wants to merge 3 commits into
Open
Mahdi-Hasan wants to merge 3 commits into
Mahdi-Hasan wants to merge 3 commits into
Conversation
Without a pages directory there is no `/_error` page, and only `/500` has a built-in status page. Client errors such as 400, 405, 412 and 416 fell through to "missing required error components" and were turned into 500. Return a plain-text body and keep the original 4xx status instead. Fixes vercel#101064 <!-- NEXT_JS_LLM -->
Mahdi-Hasan
force-pushed
the
fix/101064-app-router-4xx-status
branch
from
November 5, 2026 08:22
52c34b6 to
1d558e4
Compare
`statusCode` is `number | undefined` on the base response type. <!-- NEXT_JS_LLM -->
Mahdi-Hasan
marked this pull request as ready for review
November 5, 2026 08:37
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
In an App Router-only app (no
pages/directory), client errors that Next.js generates itself come back as 500 in production.GET /items/%E0%A4(malformed param)POST /hello.txt(public file)Range: bytes=500-600on a 6-byte public fileIf-Match: "nope"on a public fileRoute handlers that return a 4xx themselves were already fine. 404 was also fine, because it has
/_not-found.Why?
renderErrorToResponseImplinbase-server.tslooks for a page to render for the status code.STATIC_STATUS_PAGESonly contains/500, so every other code falls back to/_error. App Router-only builds have no/_error, so it throwsmissing required error components. Thecatchblock then setsres.statusCode = 500.That error is a
WrappedBuildError, which is not logged. So the server output shows nothing.How?
When no error page is found and the status is 4xx, return the standard status text (
Bad Request,Method Not Allowed, ...) astext/plainand keep the status. 5xx still goes through the existing path.Added
test/e2e/app-dir/app-router-client-error-status. It covers 400, 405, 412, 416, a route handler returning 403, and a normal 200.The new test passes locally in
startanddevmode (webpack). Without the change inbase-server.ts, the four 4xx cases fail withReceived: 500and the two control cases still pass.If you'd rather render a built-in App Router page for these codes, I'm happy to change the approach.
Fixes #101064