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
Cannot return a 404 from getInitialProps anymore by throwing an error with code='ENOENT' #11406
Comments
It seems to be related to this code having been removed in 9.3: @devknoll It seems that you removed this in your PR #10476, was this by accident, or is there now another recommended way to return statusCode 404 from getInitialProps? |
Note that throwing a |
@timneutkens This would cause the page to be rendered with a 200, I would need to research if 200 + |
It's the same thing, so yes. |
You could still accept the PR, set the "feature" to deprecated and remove it with the next major version, so that we are able use 9.3 in the meanwhile. |
I'm not saying the PR won't be merged, I'm saying you should never rely on throwing errors around. Especially when it's not documented that it's the correct way to do what you want to achieve. |
According to our SEO consultant, 200 + |
@fabb A soft 404 isn't "worse", but it could leak into search result pages...which is prevented by setting the page to "noindex". The alternative way to deal with this would be to redirect to a page that is configured to return a 404 status code. Our guide has a section on soft 404 |
Just FYI, asked Martin to weight in on this one, he's a developer advocate at Google. |
Thanks for the extra effort, much appreciated. While I‘m not happy that 404s are no longer possible, and some effort is required to change the implementation and monitoring, I understand that ENOENT is an internal implementation detail which cannot be relied on. |
@timneutkens So is it final that #11480 won't get merged, or is there still a chance to defer the "breaking" ENOENT change to next.js v10 as @andreas1327250 suggested? We're right at releasing our first SSG page, so we need to decide whether we need to refactor our dynamic pages that could be 404s now or can defer it to later. |
I haven't said that, was just pointing out that you're relying on undocumented implementation details of Next.js. We still need to review the PR. |
From an SEO perspective, this can be a huge issue. I hope you reconsider having the ability to show proper 404's as it could lead to massive problems in all websites based on Next.js. Having no way of seeing properly where we are throwing 404 is a complete lack of visibility. I don't think anyone can believe what Martin is saying here, sorry. Please, be transparent with the community with real impact on topics, being polite doesn't help. |
This is already possible, you can add I've mentioned multiple times in this thread that the way that you're triggering the 404 page through ENOENT is wrong and that if you want to use a render-based approach you have to do it in the way explained, as React runs in 1 pass and you can't just pass along You have ways to see where 404 is shown even with the render based approach, you can easily log out the routes that are rendered in that way. TLDR: |
Ok, so could I also use I‘m totally for using public api where possible, I just thought there was no other way when I implemented it using ENOENT (which was recommended in some other issue by a user). |
@estevecastells You are aware that what I'm saying is based on what actually happens in Googlebot, right? It's not "politeness" that we have this in our official guidance. Having a method to give the proper HTTP status is great but in situations where it isn't feasible we deal with that. Don't create FUD. As @timneutkens said: There are ways to generate proper 404s. This issue is about a specific situation where that isn't supported apparently and for that, we have other ways to deal with it in Googlebot. |
Ok, setting (I only have a small issue that I need to hide an ad position when the 404 is shown, but the ad position is defined in the global layout based on router path. The layout is only overridable statically for each page, so I'm not yet sure how to solve this.) |
hi @fabb, How does it work in your site? I tried set res.status = 404 in home.js getInitialProps, and then return , but it doesn't redirect to _error.js, neither to 404.js. Oh, it shouldn't render error page anymore, cause it doesn't an error page, need to use
Find it, should use UI to render a 404 component |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
Until next.js 9.2.1 I could return a 404 for a page when throwing an error with
code = 'ENOENT'
ingetInitialProps
. That no longer works in 9.3.2, now a 500 is returned. This is bad for SEO, we need to be able to throw 404s.To Reproduce
Expected behavior
Opening the page in the browser should return status code 404.
System information
Additional context
If there is another recommended way to return 404s from getInitialProps, I'd be happy about pointers.
Could the regression (or change of behavior, since
ENOENT
was kind of an internal behavior) be caused by #10572?The text was updated successfully, but these errors were encountered: