Every page results in 404 but only from cold start. Anyone else? #70582
Replies: 6 comments 10 replies
-
In Next.js, the 404 on cold start could be due to slow route initialization after inactivity. Ensure proper use of |
Beta Was this translation helpful? Give feedback.
-
Apparently not a Nextjs error, just obfuscated by Nextjs routing.
|
Beta Was this translation helpful? Give feedback.
-
For anyone else struggling with this. It turns out that next-international doesn't handle a default locale. It's supposed to. But in this combo of versions:
you have to manually set a default local in your root layout component. |
Beta Was this translation helpful? Give feedback.
-
Turns out my investigation in next-international was completely wrong. I'm still getting 404's from cold start. What seems to be happening is that Nextjs is unable to handle routing from cold start. Why this is is unclear. My middleware does contain a supabase call. So maybe there's a cold starting lambda to make this call that is timing out? |
Beta Was this translation helpful? Give feedback.
-
Where is this app deployed to? Is it using App Router or Pages Router? If its a timeout at play, does the 404 take "longer" to resolve? |
Beta Was this translation helpful? Give feedback.
-
@icyJoseph This is deployed to Vercel. It's using App router. And yes the 404 takes a few seconds to resolve. I found a work around that is highly annoying, following this guide from supabase will result in a 404 from cold start: https://supabase.com/docs/guides/auth/server-side/nextjs But if the landing page resolves without supabase, everything works fine. This should mean that cold starting Nextjs on Vercel takes so long that verifying auth from supabase causes a timeout. Making the router resolve as a 404. I didn't find a way to debug this, and for obvious reasons testing is difficult. |
Beta Was this translation helpful? Give feedback.
-
I'm having real issues debugging this since it only seems to happen on cold starts. If prod or local has not had visits for "a few hours" ANY path resolves as 404.
However once refreshed all routes will work perfectly again. I have to wait some random amount of time to see the error again. This happens even with rebooting the server locally.
I've added logging to the middleware and everything is routing fine. Just always resolving the first call as 404.
Has anyone seen this? Anyone know how to debug?
Beta Was this translation helpful? Give feedback.
All reactions