Open JanStevens opened 2 years ago
@dphang Is there any updates on this? This is causing a lot of false/positives on our prod environment
Have the same problem.
+1
Any news @JanStevens ?
I have the same issue.
We have experienced the same issue. The steps to reproduce are slightly different but generally follow the same principle.
Now that the build is complete, the page in question will return a 404 correctly. BUT now REPUBLISH the page and then REVALIDATE it via on-demand ISR. This should "fix" the earlier issues and allow the page to be navigated, however, the behavior of the OP is present. The page is seen briefly until the request is made for the JSON of the page, at which point the page immediately switches to the custom error page.
In other words, once a page is in this state, it cannot be fixed until a new deployment occurs.
We leverage a CMS so content is a bit more volatile- which increases the likelihood of our scenario occurring.
A workaround we explored is to check for process.env.CI === '1' and then fail the build if the request fo the page content fails, but this isn't an ideal scenario as it should be allowed that pages can be published/unpublished whenever.
Issue Summary
When a 404 gets triggered because of a dynamic page which does not exist, the returned json for that non existing page contains the HTML of the 404. This causes the frontend javascript code to crash resulting in a 500 error or a blank error page.
We notice that 404 pages cause javascript to crash since the retrieve page
.json
file results in a generated html file instead of a json response. Locally when we trigger a 404 we get back for the json response{notFound: true}
. This only happens when we are working with dynamic routes (eg:[...slug].tsx
).Actual behavior
In development when triggering the same 404 page the following requests are made for the url
http://localhost:3000/events/page-does-not-exist
GET /events/page-does-not-exist
is called and returns the blocking (with spinner) HTML in our case.GET /_next/data/development/en/events/page-does-not-exist.json
is called and returns the json object{notFound: true}
which causes next to request the 404 page jsonGET /_next/data/development/en/404.json
is called containing thepageProps
and the 404 page is correctly displayed.On our production environment for the same url we notice the following relevant requests:
GET /events/page-does-not-exist
is called and returns the blocking (with spinner) HTML in our case.GET /_next/data/9snNPN2gYA7NlY33qSWFq/en/events/page-does-not-exist.json
is called and returns the 404 page as HTML, this causes a crash since nextjs expect it to be jsonExpected behavior
When a page is not found we should return
{notFound: true}
instead of generating a 404 html page for a JSON responseSteps to reproduce
Have a custom 404 page with
getStaticProps
that passes some props to the 404 page. ExampleScreenshots/Code/Configuration/Logs
Versions
Additional context
serverless.yml
Checklist
latest
oralpha
@sls-next/serverless-component
release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the oldserverless-next.js
component and theserverless-next.js
plugin are deprecated and no longer maintained.