-
Notifications
You must be signed in to change notification settings - Fork 86
fix: ISR 404 pages should be cached ephemerally #2233
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
Conversation
✅ Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-export-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for nextjs-plugin-custom-routes-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for next-plugin-edge-middleware ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for next-plugin-canary ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for next-i18next-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a solid quick fix until we have proper cache headers. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks!
Description
In Next.js it's possible to make an ISR 404 page that revalidates after a period of time.
A 404 page will be served in a number of scenarios, including (but not limited to):
notFound: true
fallback: false
id
1 and 2 prerendered andfallback: false
notFound: true
id
4 matches a condition that returnsnotFound: true
Currently, on Netlify, we have inconsistent behavior in these different scenarios. An ISR 404 page will behave like an SSR page in the first 2 scenarios, a static page in the 3rd scenario and an ISR page without a TTL in the last scenario (which is particularly problematic because the
notFound
logic might change due to some external state changing (e.g. CMS content), but the 404 will remain indefinitely and the route will never be revalidated).These behaviors occur for the following reasons:
fallback: false
are only intended to serve prerendered paths on the route, therefore we currently redirect the entire route to the statically rendered 404 page on the CDN (relying on the CDN to serve the prerendered HTML pages instead of following the redirect)notFound: true
will serve an ISR 404 page, but Next.js does not usestale-while-revalidate
headers in this case, unlike other ISR content, and this prevents us from identifying the response as ISR and extracting the TTLThis PR adds a special case to the TTL logic and assumes that if the route is an ODB route and the status code is 404, then we should only cache the response ephemerally for 60s. It is a stopgap solution designed to limit the impact of point 3 above. With the PR, an ISR 404 will no longer be cached indefinitely, however it will still not respect that actual TTL specified in the
revalidate
value. This PR does not address points 1 and 2 above, which will be tackled as part of forthcoming changes to the caching implementation.Tests
Tests added