next.js
0950e8ae - Return plain text 404 for non-document requests to unknown paths (#95930)

Commit
43 days ago
Return plain text 404 for non-document requests to unknown paths (#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?
Author
Parents
Loading