opennextjs-netlify: [Bug]: Fallback false is ignored
Summary
Netlify triggers a new ODB function instead of returning the expected 404 when using fallback: false.
Context:
We have a top level dynamic route, so that we can create new landing pages directly from our CMS. Because fallback: false was ignored, every request to myWebsite.com/:uid resulted in a new ODB function being triggered. However, these requests were for example also triggered by crawlers requesting robots.txt (which was missing at that time). Another edge case leading to a huge number of function invocations was the usage of the nextjs Link component for a route with a configured redirect (in _redirects). Because Nextjs prefetches routes, it tried to prefetch the JSON of the route (which didn’t exist because it’s a redirect). This would not have been a problem (only a failed request in the network tab of the browser, and it can be fixed by disabling the prefetching)…However, with Netlify ignoring fallback: false, a new ODB function was spawned for every prefetch request (which could be many per user session).
All in all we accumulated 170k+ function invocations in one weekend. I know that the above described scenario is very specific (and could have been avoided) but I wanted to emphasize, that the i18n fix can result in some unpleasent surprises for Netlify customers that use fallback: false and expect it to work as described in the nextjs docs.
Steps to reproduce
.
A link to a reproduction repository
No response
Plugin version
4.2.1
More information about your build
- I am building using the CLI
- I am building using file-based configuration (
netlify.toml)
What OS are you using?
No response
Your netlify.toml file
`netlify.toml`
# Paste content of your `netlify.toml` file here
Your public/_redirects file
`_redirects`
# Paste content of your `_redirects` file here
Your next.config.js file
`next.config.js`
# Paste content of your `next.config.js` file here. Check there is no private info in there.
Builds logs (or link to your logs)
Build logs
# Paste logs here
Function logs
Function logs
# Paste logs here
.next JSON files
generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 33 (7 by maintainers)
Commits related to this issue
- fix(404): Attempt to catch 404 manually This applies the fix found here: https://github.com/netlify/next-runtime/issues/1179 https://joelmturner.com/blog/static-nextjs-netlify-500-errors-404-errors — committed to freelawproject/free.law by mlissner 4 years ago
- fix(404): Attempt to catch 404 manually This applies the fix found here: https://github.com/netlify/next-runtime/issues/1179 https://joelmturner.com/blog/static-nextjs-netlify-500-errors-404-errors — committed to freelawproject/free.law by mlissner 4 years ago
- fix(404): Attempt to catch 404 manually This applies the fix found here: https://github.com/netlify/next-runtime/issues/1179 https://joelmturner.com/blog/static-nextjs-netlify-500-errors-404-errors — committed to freelawproject/free.law by mlissner 4 years ago
I don’t like being a +1 dude, but +1.
Thanks @hu0p for the additional information and use cases, much appreciated. We have been looking into this and have a potential way forward that should ensure non-prerendered dynamic routes will bypass the ODB handler when
fallback: falseis set. There’s a few additional cases in the comments above that I want to make sure we’ve covered before we push anything, but I will update here with more info soon.@ascorbic any news on this? Would be great to know if we have to find a workaround ourselves, or if a fix from Netlify’s side is planned. Thanks!
@JohnGemstone Our solution looked something like this:
I hope this helps. This may or may not be directly applicable to your use-case, but we have an SDK that makes requests inside
getStaticPropswhich chooses to throw when it encounters an error. This is the desired outcome during the build, but not during production which seems to lead to the pain a lot of us are encountering in this thread. To make matters worse, this is not idiomatic Next.js. As I understand itfallback: falseand especially the absence of an arbitrary path in getStaticPaths should mean there is no function hit.@orinokai is working on this
Good idea. Updated!
The PR is really useful, thanks @hu0p. We will get it merged in and, as you say, it will be useful for testing. The specific error happens because
getStaticPropsruns on those pages and there is no write file access in the function environment. The fix is still in progress as the edge cases are proving tricky - we need need ensure that the handler function is completely bypassed for non-prerendered dynamic-routes withfallback: falsebut we also need to ensure custom 404 pages are respected in all locales and provide support for ISR 404 pages with revalidate. Will keep you posted on progress.@inadeqtfuturs Same. I had really hoped this would’ve been solved by now. The workaround works for small cases like wrapping an SDK but it doesn’t scale well for complex logic or some fairly common use-cases. We really began to understand this when we ran into a use-case similar to @pixelino’s.
We now have an i18n site that reuses responses from getStaticPaths in getStatpicProps via filesystem-based caching. The ODB handler will attempt to SSR a page that it shouldn’t (due to
fallback: falseconfig) and subsequently choke because the file path doesn’t exist. This of course builds fine locally but doesn’t work in production because the files aren’t there. Including the files, in public/ or in the function itself, doesn’t seem like a viable solution because it would amount to 132 mb of serialized data (far exceeding Netlify’s function size limit).Couple questions for anyone experiencing this bug:
Heck, react to my comment with a heart if yes for 1, a tada/confetti if yes for 2, and a thumbs down if no to both to make it easy 😁. It seems like this problem pops up under a couple different conditions, so my hope is that if we can narrow down the problem set we can figure out the origin of the issue.
@orinokai or @ascorbic I’m willing to volunteer some more of my time to investigate this. Hopefully the existing large site we have could serve as a test-case for this.
Has anything changed on this front? It seems like it could be a big part of the problem.
Anything new about this bug? I still have this problem. Dynamic routes are returning server error 5xx, instead of a regular 404 page.