-
Notifications
You must be signed in to change notification settings - Fork 27.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
next/navigation notFound() function do not apply HTTP 404 status code #51021
Comments
Is there a workaround for this? Will this be fixed? |
Two things were causing this behavior on my project:
Anyway, hope this is relevant to someone. |
@caiolrm Thank you for the tipp. I just removed the dynamic route and copy and pasted all files for every |
@ijjk Sorry for involving you, but will this ever be fixed? This is a terrible, reproducible bug, that's been open for half a year. Wrong status-codes served by a webserver should be a core concern. The only way to workaround it is to not use dynamic routes. At that point I can go back to nginx/apache2. |
Same here... Are we seriously not able to set 404 status codes? The docs for
But it clearly doesn't work. |
@Enngage The issue is with the compbination of caching and dynamic routes. If you route uses I suspect this is why it wasn't fixed yet. It is too complex to reproduce. |
Hey, it doesn't return 404 on first load... that's the problem because then google indexes the page. It's true we are using dynamic routes with url parameters. We actually "solved" it by creating a "/404" route and redirected |
We are redirecting from server straight to '/404' route which applies the 404. Its the only way we could achieve 404 response status code and stop google from indexing every single path even if it does not exist. I wish the 'notFound' method worked as documented, but it doesn't. |
Can you show us the function you use to do the redirect?
|
We are using |
This bug seems like a huge pain. Maybe I'm missing something, but how are you supposed to use dynamic routes if they can't be 404'd? |
Is this also fixed by #55542? |
@caiolrm , thanks for the tip! I removed loading.tsx and it worked. |
I have the same issue , i call notFound() but my doc of page is return 200 status code , how can change that to 404 ????? |
Next js 14 is so popular i wonder how such an issue is still present on the framework logic.. please put this as high priority we need 404 status code after loading not found pages! |
We were also experiencing this issue and as mentioned by @caiolrm, removing the Digging a little deeper we found the issue was actually being caused by This also incidentally fixed an issue we were experiencing with |
Also experiencing the same issue. Our structure looks like this and this will recreate the problem: app By removing the loading.js page the issue goes away and 404 is returned instead of 200 status for the not found page (for both client side and server side). This is a serious issue as it forces you to choose between User Experience (loading page) and SEO (where 404s are critical for crawl budget and clarity) - two of the main reasons we chose Next JS. If anyone can look into/resolve this (e.g. @balazsorban44 ), we'd be very grateful. |
@GXM245, as a compromise - you can use something like progress bar: https://www.npmjs.com/package/next13-progressbar?activeTab=code (or write something similar by yourself). You can see such solution on github too. So there is no loading.js, but there is still an effect of loading state when clicking internal links. |
Thanks @MaciejWira! I'll take a closer look at that - and yes, you're right, the most suitable option at this point would be to write something ourselves. I wonder how many of us have similar setups but unaware that our pages are, in fact, returning a 200 when they should be a 404. I only discovered this myself after a SEO crawl where a load of pages I expected to be a 404 were returning a 200. @timneutkens would you be able to lend us your ear on this one? This is quite fundamental to the response codes that core Next JS functionality returns. |
So right now Nextjs starts streaming data immediately with loading.js and because how the web works it has to have a status code 200. Later on while processing the data we decide it should be a notfound (which is cool btw) and can't change the status code. |
the same issue with |
### What In static generation phase of app page, if there's any case that we're receiving 3xx/4xx status code from the response, we 're setting it into the static generation meta now to make sure they're still returning the same status after build. ### Why During static generation if there's any 3xx/4xx status code that is set in the response, we should respect to it, such as the ones caused by using `notFound()` to mark as 404 response or `redirect` to mark as `307` response. Closes NEXT-2895 Fixes #51021 Fixes #62228
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64 Binaries: Node: 18.13.0 npm: 8.19.3 Yarn: N/A pnpm: N/A Relevant packages: next: 13.4.4 eslint-config-next: 13.3.0 react: 18.2.0 react-dom: 18.2.0 typescript: 5.0.4
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true), Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue or a replay of the bug
https://codesandbox.io/p/sandbox/cranky-pine-f9s292?file=%2Fapp%2Fpage.tsx%3A1%2C1
To Reproduce
Describe the Bug
When notFound is called, the 404 page is correctly displayed, but the status is 200 :
Expected Behavior
The HTTP status code should be 404
Which browser are you using? (if relevant)
Chrome Version 114.0.5735.106 (Build officiel) (x86_64)
How are you deploying your application? (if relevant)
next start
The text was updated successfully, but these errors were encountered: