Intermittent "Not Found 404" returned on first visit after idle time (Next 15 With App Router) #82839
-
Description of the bugOn the first visit to a page after some idle time (usually 1–2 hours is enough), I sometimes receive the default Next.js 404 page, even though the page definitely exists. If I refresh the page, it loads correctly 100% of the time. The affected path is Here is a log from one of these failures:
All inner requests return 200, but the overall response is a 404. As mentioned, this only happens after the app has been idle for 1–2 hours, and it’s easy to reproduce by visiting a direct link. Example of a link that may return 404 on first time: It doesn’t happen every single time, but it happens often enough to affect real users. I initially suspected a firewall issue, but logs show that isn’t the cause... (apparently) While not critical (since refreshing always fixes it), this significantly worsens user experience, especially because many of our clients share direct links in WhatsApp groups. Expected behaviorIt should never return 404 on a page that 100% exists and all inner requests have been successful. And in case of failure, it should use the custom not-found for that path. Environment
Steps to reproduceGo to this link in production, it may fail as described. If it does not fail, try another browser agent. But should definetly fail on first visit on many users: https://athletiks.io/ca/events/run-music-con-camilo-10-dagost-del-2025-3de5b3 Additional informationNo response Examplehttps://athletiks.io/ca/events/run-music-con-camilo-10-dagost-del-2025-3de5b3 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
-
|
Finally I found the problem. It was in the middleware.ts, and it was caused because Supabase auth overwrote the headers from next-intl, exactly what’s explained here: #70582 (comment) In my case, I decided to simply not recreate a new response after Supabase sets the cookies. That solved the issue immediately 👇 |
Beta Was this translation helpful? Give feedback.



Finally I found the problem.
It was in the middleware.ts, and it was caused because Supabase auth overwrote the headers from next-intl, exactly what’s explained here: #70582 (comment)
In my case, I decided to simply not recreate a new response after Supabase sets the cookies. That solved the issue immediately 👇