Repository navigation
Return plain text 404 for non-document requests to unknown paths - #95930
Merged
Merged
Conversation
Contributor
Stats from current PR🔴 3 regressions
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📝 Changed Files (1 file)Files with changes:
View diffsserver.runtime.prod.jsDiff too large to display 📎 Tarball URLCommit: d2ea04f |
Contributor
Tests PassedCommit: d2ea04f |
gaearon
force-pushed
the
gaearon-not-found
branch
2 times, most recently
from
July 19, 2026 00:33
1a2b6ab to
28175f4
Compare
elliott-with-the-longest-name-on-github
pushed a commit
to sveltejs/kit
that referenced
this pull request
Jul 21, 2026
… subresource requests (#16463) closes #13734 Diagnosis in the issue. Requests whose `Sec-Fetch-Dest` can never render HTML now get a plain `Not Found` with `Vary: Sec-Fetch-Dest` instead of the SSR'd error page, same shape as the `/_app/` 404 a few lines up. Absent header, `empty`, `document` and unknown values are unchanged. Also fixes the stale Safari comment in `errors.js` (sec-fetch-dest ships since 16.4). Prior art: vercel/next.js#95930, vitejs/vite#20866. Note: `handleError` no longer runs for these (the default hook discards them anyway).
gaearon
force-pushed
the
gaearon-not-found
branch
3 times, most recently
from
July 22, 2026 12:54
fd931f3 to
eb2fc4b
Compare
eps1lon
reviewed
Jul 22, 2026
gaearon
force-pushed
the
gaearon-not-found
branch
from
July 22, 2026 15:05
768b5bc to
85ece44
Compare
gaearon
commented
Jul 22, 2026
| export function isNonHtmlSecFetchDest( | ||
| value: string | string[] | null | undefined | ||
| ): boolean { | ||
| return typeof value === 'string' && NON_HTML_SEC_FETCH_DESTS.has(value) |
Contributor
Author
There was a problem hiding this comment.
This could also be an allowlist instead like Vite does. vitejs/vite#20866
Blocklist felt a bit safer but maybe I'm being overly cautious
gaearon
force-pushed
the
gaearon-not-found
branch
6 times, most recently
from
July 23, 2026 23:25
c6bef1c to
9764ca0
Compare
Requests for subresources like images or fonts (e.g. icons listed in a web app manifest) currently render the full HTML not-found route when the path doesn't match anything, even though the response body can never be displayed. In dev this also triggers on-demand compilation of the not-found route, so a single missing manifest icon can cost seconds per request. Short-circuit the 404 handling when the request's Sec-Fetch-Dest indicates a destination that can't render HTML (image, font, manifest, style, script, media, workers) and return a plain text 404, matching the existing behavior for missing /_next/static assets. This is done in two places: the router server catchall (next dev / next start), and the base server's 404 render path for minimal mode, where the platform routes unmatched paths directly to the not-found render. Document navigations, iframes, fetch/XHR (including RSC requests, which always use the "empty" destination since Sec-Fetch-* headers are forbidden for fetch()), and clients that don't send the header are unaffected and still render the not-found route.
Deployment platforms invoke the compiled not-found route entry directly through its handler export, without going through the router server or base server, so the plain text 404 short-circuits didn't apply when deployed and subresource requests to unknown paths still rendered the not-found route. Add the same check to the app page template handler when it serves the not-found route. Verified against a deployed app that manifest icon and favicon requests no longer render the not-found route while document and RSC requests are unaffected. The adapter test invokes the compiled route entry the way platforms do, and the dynamic e2e suite asserts the plain text 404 in deploy mode where the platform can't serve a prerendered 404.
Resume requests for postponed shells use POST and must not be intercepted. Also make the dynamic not-found fixtures build with cache components by moving the dynamic access behind Suspense, so the suites run in both modes. When deployed with cache components the platform serves the prerendered not-found shell without invoking Next.js, which the dynamic suite asserts in that mode.
gaearon
force-pushed
the
gaearon-not-found
branch
from
July 23, 2026 23:44
9764ca0 to
d2ea04f
Compare
gnoff
approved these changes
Jul 23, 2026
m-kawafuji
pushed a commit
to m-kawafuji/next.js
that referenced
this pull request
Aug 8, 2026
…cel#95930) Not sure if there's any downside to this. Currently, there are situations when a browser requests something in a particular format: - Favicons - Manifest icons - `<img>` with broken `src` - Wrong `<link>`s - `new Worker()` These requests have a `Sec-Fetch-Dest` header which can definitely exclude things that can't be HTML. My proposal is to not return the HTML for them (even in dev) so that this doesn't waste time in case rendering the root layout is slow or expensive. Less work for the server, whether dev or prod. I believe this was happening in dev, and in prod if rendering `not-found` requires something dynamic (e.g. in the root layout). And for static self-hosted, I believe it would respond with static HTML. After this change, we don't render the HTML. ## Before Image in manifest hits the real `/not-found` route and runs application code: <img width="1055" height="639" alt="Screenshot 2026-07-19 at 00 23 01" src="https://github.com/user-attachments/assets/869f85f8-a009-4266-a345-74e3342adb41" /> Notice 404 at the end with 2 seconds in application code. ## After Image in manifest is still 404 but doesn't hit any app code. <img width="1033" height="696" alt="Screenshot 2026-07-19 at 00 21 17" src="https://github.com/user-attachments/assets/3a1817b4-f050-45c0-93ca-0507cf9de803" /> It's maybe a bit weird it doesn't show in the terminal log. In that sense it's like `/_next/static/` because it's handled at an earlier layer. Maybe we could still log it but it would have to happen from a different place, and also breaks consistency, so I opted with keeping it hidden. --- I can't see any coherent arguments for why this should reach the app render so this should be OK?
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Not sure if there's any downside to this.
Currently, there are situations when a browser requests something in a particular format:
<img>with brokensrc<link>snew Worker()These requests have a
Sec-Fetch-Destheader which can definitely exclude things that can't be HTML. My proposal is to not return the HTML for them (even in dev) so that this doesn't waste time in case rendering the root layout is slow or expensive. Less work for the server, whether dev or prod.I believe this was happening in dev, and in prod if rendering
not-foundrequires something dynamic (e.g. in the root layout). And for static self-hosted, I believe it would respond with static HTML.After this change, we don't render the HTML.
Before
Image in manifest hits the real
/not-foundroute and runs application code:Notice 404 at the end with 2 seconds in application code.
After
Image in manifest is still 404 but doesn't hit any app code.
It's maybe a bit weird it doesn't show in the terminal log. In that sense it's like
/_next/static/because it's handled at an earlier layer. Maybe we could still log it but it would have to happen from a different place, and also breaks consistency, so I opted with keeping it hidden.I can't see any coherent arguments for why this should reach the app render so this should be OK?