You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
App Router renders the full not-found page for subresource requests to unmatched paths #5132
A GET/HEAD request for an unmatched path whose Sec-Fetch-Dest is a non-HTML subresource destination (image, font, script, manifest, and so on) compiles and renders the full not-found page in the App Router.
Next.js short-circuits these requests before invoking the not-found route and returns the plain-text Not Found body it already uses for invalid _next/static/* paths. That avoids a full HTML render for what is almost always a browser auto-requesting a stale or missing subresource, for example a manifest icon referenced by an old build.
vinext responds with the rendered not-found HTML; Next.js responds with a plain-text 404.
Expected
Same as Next.js; see its test/e2e/app-dir/not-found-non-document-dynamic. Document and empty-dest (fetch/RSC) requests keep rendering the custom not-found page.
I could reproduce this with an App Router app that has a custom not-found. Requesting an unmatched path such as /does-not-exist.png with Sec-Fetch-Dest: image (also font, manifest or style) returns a 404 with the rendered not-found HTML. Recent Next.js releases (16.4.6 and 16.5.0, for example) check Sec-Fetch-Dest for GET/HEAD requests to unmatched paths and return a plain-text Not Found 404 without rendering the not-found route. vinext's unmatched-route handling has no such check; the only shortcut it takes is for /favicon.ico in dev. Document requests, and fetch/RSC requests (empty destination), still render the custom not-found page as expected.
Details for maintainers
Cause: On an unmatched path, the vinext App Router renders the full custom not-found page even when Sec-Fetch-Dest names a non-HTML subresource (image, font, manifest, style). The published Next.js 16.4.6 and 16.5.0 packages instead return a plain-text Not Found 404, via isNonHtmlSecFetchDest() in router-server.js and base-server.js. Nothing in packages/vinext/src reads Sec-Fetch-Dest. Next.js behaviour comes from the npm packages, since there was no .nextjs-ref clone. Only the dev server was tested, not the production server or the Workers entry.
Where to look:
packages/vinext/src/server/app-rsc-handler.ts:3271 the if (!match) branch before renderUnmatchedRoute(): add Next.js's NON_HTML_SEC_FETCH_DESTS check for GET/HEAD here, next to the existing dev favicon shortcut. Next.js returns text/plain Not Found and, in base-server, a private no-store Cache-Control.
Not in the repository: Next.js reference: dist/server/lib/is-non-html-sec-fetch-dest.js, router-server.js (~line 636) and base-server.js (~line 1570) in next@16.5.0
Reproduction:npx vp test run tests/app-not-found-non-document.test.ts
The command exited with 1 on a clean checkout.
Expected: A GET/HEAD to an unmatched App Router path with a non-HTML Sec-Fetch-Dest (image, font, manifest, style, ...) returns 404 with Content-Type text/plain and body Not Found, without rendering not-found. Observed: vinext returns 404 with Content-Type text/html; charset=utf-8 and the rendered custom not-found page.
The test: tests/app-not-found-non-document.test.ts
/** * Issue #5132: a GET/HEAD for an unmatched App Router path whose * `Sec-Fetch-Dest` is a non-HTML subresource destination (image, font, ...) * should get Next.js's plain-text `Not Found` 404 instead of the rendered * `not-found` page. * * Next.js (16.5.0): `packages/next/src/server/lib/router-server.ts` and * `base-server.ts` short-circuit with `isNonHtmlSecFetchDest()`. * Ported from Next.js: test/e2e/app-dir/not-found-non-document-dynamic */importhttpfrom"node:http";importtype{ViteDevServer}from"vite";import{afterAll,beforeAll,describe,expect,it}from"vite-plus/test";import{APP_FIXTURE_DIR,startFixtureServer}from"./helpers.js";functionget(url: string,headers: Record<string,string>,method="GET",): Promise<{status: number;contentType: string;body: string}>{returnnewPromise((resolve,reject)=>{constreq=http.request(url,{ method, headers },(res)=>{letbody="";res.setEncoding("utf8");res.on("data",(chunk)=>(body+=chunk));res.on("end",()=>resolve({status: res.statusCode??0,contentType: String(res.headers["content-type"]??""),
body,}),);});req.on("error",reject);req.end();});}describe("App Router not-found for non-document subresource requests",()=>{letserver: ViteDevServer;letbaseUrl: string;beforeAll(async()=>{({ server, baseUrl }=awaitstartFixtureServer(APP_FIXTURE_DIR));awaitget(`${baseUrl}/`,{});},120_000);afterAll(async()=>{awaitserver?.close();});// `script` is left out: Vite's dev transform middleware treats it specially.for(constdestof["image","font","manifest","style"]){it(`returns a plain-text 404 for Sec-Fetch-Dest: ${dest}`,async()=>{constres=awaitget(`${baseUrl}/does-not-exist-5132.png`,{"sec-fetch-dest": dest});expect(res.status).toBe(404);expect(res.contentType).toMatch(/^text\/plain/);expect(res.body).toBe("Not Found");},60_000);}it("still renders the custom not-found page for documents",async()=>{constres=awaitget(`${baseUrl}/does-not-exist-5132`,{"sec-fetch-dest": "document",accept: "text/html",});expect(res.status).toBe(404);expect(res.body).toContain("404 - Page Not Found");},60_000);});
What it printed
RUN v5.1.0 /workspace/repo
stdout | tests/app-not-found-non-document.test.ts > App Router not-found for non-document subresource requests
[vinext] Auto-injected @mdx-js/rollup for MDX support
GET / 200 in 15.6s (compile: 13.7s, render: 1.9s)
GET /does-not-exist-5132 404 in 22ms
❯ unit tests/app-not-found-non-document.test.ts (5 tests | 4 failed) 16700ms
❯ App Router not-found for non-document subresource requests (5)
× returns a plain-text 404 for Sec-Fetch-Dest: image 236ms
× returns a plain-text 404 for Sec-Fetch-Dest: font 27ms
× returns a plain-text 404 for Sec-Fetch-Dest: manifest 24ms
× returns a plain-text 404 for Sec-Fetch-Dest: style 23ms
✓ still renders the custom not-found page for documents 25ms
Test Files 1 failed (1)
Tests 4 failed | 1 passed (5)
Start at 09:40:13
Duration 19.15s (tests 88%, transform 7%, import 4%, setup 1%)
stderr | tests/app-not-found-non-document.test.ts > App Router not-found for non-document subresource requests
[vinext] Found 5 external rewrites that proxy requests to external origins:
/external-headers/before-files/:path* → http://127.0.0.1::upstreamPort/:path*
/proxy-external-host-capture → http://:proxyHost.invalid/host-capture
/proxy-external-path-capture → http://127.0.0.1::upstreamPort/public/:file?revision=published
/external-headers/after-files/:path* → http://127.0.0.1::upstreamPort/:path*
/external-headers/fallback/:path* → http://127.0.0.1::upstreamPort/:path*
Request headers, including credential headers (cookie, authorization, proxy-authorization, x-api-key), are forwarded to the external origin to match Next.js behavior. If you do not want to forward credentials, use an API route or route handler where you control exactly which headers are sent.
stderr | tests/app-not-found-non-document.test.ts > App Router not-found for non-document subresource requests
The "middleware" file convention is deprecated. Please use "proxy" instead.
To migrate automatically, run:
npx @next/codemod@canary middleware-to-proxy .
Learn more: https://nextjs.org/docs/messages/middleware-to-proxy
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 4 ⎯⎯⎯⎯⎯⎯⎯
FAIL unit tests/app-not-found-non-document.test.ts > App Router not-found for non-document subresource requests > returns a plain-text 404 for Sec-Fetch-Dest: image
FAIL unit tests/app-not-found-non-document.test.ts > App Router not-found for non-document subresource requests > returns a plain-text 404 for Sec-Fetch-Dest: font
FAIL unit tests/app-not-found-non-document.test.ts > App Router not-found for non-document subresource requests > returns a plain-text 404 for Sec-Fetch-Dest: manifest
FAIL unit tests/app-not-found-non-document.test.ts > App Router not-found for non-document subresource requests > returns a plain-text 404 for Sec-Fetch-Dest: style
AssertionError: expected 'text/html; charset=utf-8' to match /^text\/plain/plain
- Expected:
/^text\/plain/
+ Received:
"text/html; charset=utf-8"
❯ tests/app-not-found-non-document.test.ts:57:31
55| const res = await get(`${baseUrl}/does-not-exist-5132.png`, { "s…
56| expect(res.status).toBe(404);
57| expect(res.contentType).toMatch(/^text\/plain/);
| ^
58| expect(res.body).toBe("Not Found");
59| }, 60_000);
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/4]⎯
A pull request fixes this, with the reproduction kept as a regression test. ask-bonk[bot] approved its head, and its checks pass: it is waiting for a maintainer.
Activity
alcora-dev commentedon Dec 5, 2026
Triage: reproduced
I could reproduce this with an App Router app that has a custom
not-found. Requesting an unmatched path such as/does-not-exist.pngwithSec-Fetch-Dest: image(alsofont,manifestorstyle) returns a 404 with the rendered not-found HTML. Recent Next.js releases (16.4.6 and 16.5.0, for example) checkSec-Fetch-Destfor GET/HEAD requests to unmatched paths and return a plain-textNot Found404 without rendering the not-found route. vinext's unmatched-route handling has no such check; the only shortcut it takes is for/favicon.icoin dev. Document requests, and fetch/RSC requests (empty destination), still render the custom not-found page as expected.Details for maintainers
Cause: On an unmatched path, the vinext App Router renders the full custom not-found page even when Sec-Fetch-Dest names a non-HTML subresource (image, font, manifest, style). The published Next.js 16.4.6 and 16.5.0 packages instead return a plain-text
Not Found404, via isNonHtmlSecFetchDest() in router-server.js and base-server.js. Nothing in packages/vinext/src reads Sec-Fetch-Dest. Next.js behaviour comes from the npm packages, since there was no .nextjs-ref clone. Only the dev server was tested, not the production server or the Workers entry.Where to look:
packages/vinext/src/server/app-rsc-handler.ts:3271theif (!match)branch before renderUnmatchedRoute(): add Next.js's NON_HTML_SEC_FETCH_DESTS check for GET/HEAD here, next to the existing dev favicon shortcut. Next.js returns text/plainNot Foundand, in base-server, a private no-store Cache-Control.packages/vinext/src/server/app-rsc-response-stage.ts:251renderNotFound for theapp-not-foundresponse stage (Workers/prod path) may need the same check.Reproduction:
npx vp test run tests/app-not-found-non-document.test.tsThe command exited with 1 on a clean checkout.
Expected: A GET/HEAD to an unmatched App Router path with a non-HTML Sec-Fetch-Dest (image, font, manifest, style, ...) returns 404 with Content-Type text/plain and body
Not Found, without rendering not-found.Observed: vinext returns 404 with Content-Type text/html; charset=utf-8 and the rendered custom not-found page.
The test: tests/app-not-found-non-document.test.ts
What it printed
Triaged by an AI agent at 5974ee6; it may be wrong. Confidence: high. · Triage report · Run #136
alcora-dev commentedon Dec 5, 2026
A fix is ready for review: #5135
A pull request fixes this, with the reproduction kept as a regression test. ask-bonk[bot] approved its head, and its checks pass: it is waiting for a maintainer.
Fixed by an AI agent; it may be wrong. · Triage report · Run #1266