next.js: Routes using data fetching methods return 304 on non-conditional requests
Link to the code that reproduces this issue
https://github.com/kevineinarsson/next-revalidate-issue
To Reproduce
-
Start the application in production mode (build & start)
-
Curl one of the routes:
curl -I http://localhost:3000 (static)
curl -I http://localhost:3000/1 (dynamic)
These should return 200:s, no matter how many times you curl. Note the x-nextjs-cache header which indicates whether a revalidation of the content is performed (due to fetch options including next: { revalidate: 5 })
curl -I http://localhost:3000 -H 'If-None-Match: "<etag from previous request>"'
curl -I http://localhost:3000/1 -H 'If-None-Match: "<etag from previous request>"'
This should return a 304, since we’re matching against an ETag and the content matches.
However, if a revalidation occurs from a request that includes a If-None-Match header, the .meta will now contain status: 304, causing subsequent requests without an ETag to return 304 not modified, which should not happen.
Current vs. Expected behavior
Cache updates should not store conditional headers such as 304. The result of the operations above should be a 200 in the metadata file.
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023
Binaries:
Node: 20.6.1
npm: 10.1.0
Yarn: 1.22.19
pnpm: 8.7.5
Relevant Packages:
next: 13.5.4
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: 5.1.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Not sure
Additional context
Issue does not appear on 13.4.17.
In dynamic routes, removing generateStaticParams() makes the problem disappear, but doing so leads to a response without an ETag.
Using export const dynamic = 'force-dynamic'; works for static pages, but of course makes them dynamic.
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Reactions: 66
- Comments: 80 (6 by maintainers)
Commits related to this issue
- Downgrade next to 13.4.12 to fix the 304 Not Modified issue: https://github.com/vercel/next.js/issues/56018 — committed to jasnlink/msmtech.ca by jasnlink 8 months ago
- コレを頼りにNext.jsのバージョンを下げた https://github.com/vercel/next.js/issues/56018 — committed to barubora3/nft-distribution-demo by barubora3 8 months ago
- Fix refresh 304 empty page - https://github.com/vercel/next.js/issues/54782 에 따르면, 싱글턴 모듈은 요청 시 유실될 수 있으므로, 매번 생성될 수 있도록 하는것이 좋다고는 하다. - 또 다른 관련문서: https://github.com/vercel/next.js/issues/55660 http... — committed to LimEunSeop/silverflame by LimEunSeop 8 months ago
Same. I didn’t want to post anything as it looks there are enough of us here with the same problem, but its clear as a day that nobody cares so I’m posting.
So yeah, there’s a serious problem with Nextjs’s caching. Which is a core feature, and it totally gets ignored. Ridiculous really. Invested months in Nextjs as our go-to React framework for the future but everything points in the direction that this project shouldn’t be trusted. It’s unfathomable to me that a project this big is having such a huge issue with it’s main feature and nobody cares. Nobody replies to GitHub issues. 🤦
Dozens of canary releases per day full of features and fixes but the core feature (caching) is buggy to the extent of not being usable at all and nobody is working on that 👎
Shame!
An update to NextJS 14 is required to avoid this issue.
We ran into the same issue (13.5.1 with app folder on production and self-hosted with standalone build) were some of our static routes with
export const revalidate = XX;started returning http 304 codes and users would only see a white, blank page or if directly called via url bar nothing at all.As a workaround we resorted to using
export const dynamic = 'force-dynamic';on these routes instead of revalidating the static routes. That seems to resolve this bug for the moment but of course isn’t what we would like to do.Also hitting this.
Made my own repro here, https://github.com/akd-io/bug-304, which is just
create-next-app+ changeapp/page.tsxto:same issue with 13.5.4
Tried a few hours ago, still reproducible with 14.0.1-canary.0
Exact same problem here… Wasted me days of time trying to figure out what went wrong as there’s no error log or anything…
Please fix this as soon as possible.
Same problem in production on 13.4.19 and 13.5.4.
Getting 304, Not Modified and empty response bodies.
Downgraded all the way to 13.4.12 until this is fixed.
🎉 My reproduction repo https://github.com/akd-io/bug-304 now works with 14.0.2
We encounter the same symptoms, reproducible on
14.0.1-canary.0Unlike the OP, we do not use dynamic routes & generateStaticParams. Instead we just use
fetchon a regular app route:I’ve been racking my brain for hours. I chose NextJS for a new project and after deploying it some pages started to go blank.
To be honest I don’t understand how a bug as big as this can happen in a framework like NextJS… I fixed it downgrading to
13.4.19Same happening here. We literally cannot update to any new release. We can’t have production broken. Very urgent!
Same here. We are trying a new NextJs version each time it release and it’s broken each time. Still using 13.4.19.
I face same issue after upgrading to 13.5.3
After 12 hours on prod same error with 304 response on version 14.0.3 =(
@samurodriguez Try upgrading to the latest 14.0.2 tag that was pushed today which has the fix included. We have been running it in production and fixed our issue.
I could not reproduce it using this repo https://github.com/kevineinarsson/next-revalidate-issue and updated to 14.0.2-canary.3 . So it seems to be fixed.
Same
Just tested 14.0.2-canary.3 and waiting to see if this is it. Meanwhile noticed a series of this going on (test/production/app-dir-prevent-304-caching/app/), related with 304 caching on that repo Let’s hope this is it.
Took forever to find out what was happening. We are having the same issue. Next 13.5.6, standalone production build. 304 response status after some server up-time on specific routes. Private browser windows render blank pages.
We use 13.4.5, and it’s also works fine
We’re facing a similar issue. We upgraded to version 13.5.3 to address memory leaks, but now we’re encountering the 304 code and a white screen after revalidation.
@smuk3c says it’s still in 14.0.4 and that is as far as I can tell, the most recent version. So, it appears that it’s not certain that it’s fixed.
Potentially fixed in 14.0.2-canary.3 with this commit which was linked to a very similar issue: https://github.com/vercel/next.js/commit/74153e1208e0f3cab8fa736e9192fd3ff7ad12cc Anyone checked yet?
Same problem after upgrading from 13.4.19 to 14.0.0, waiting for a fix, thanks!
Thanks
It’s still present in 13.5.6 standalone production mode. reverted to 13.4.19
We have the same problem for all
13.5.xand are stuck on13.4.19. It only happens in production, and we are not able to reproduce it locally.I am using pnpm here !
npm run build can help in my experience, rather than using yarn run build.
We faced this issue in 13.5.4.
304 with blank page.
We are running Next.js server on docker container instead of getting hosted on Vercel.
We disabled caching for now.
We have a catch-all dynamic route
[...path]withgenerateStaticParamsandgenerateMetaData.Then we do a
next build(standalone) and deploy that to Azure ASE on a linux docker container and fire up the server usingnode server.js.So, for all the statically generated pages we get a
200 OKbut it seems the ones generated on the fly seems to return304 Not Modifiedeither straightaway or after a while.But, once you get a
304 Not Modifiedheader on the client (browser), you start to see a blank page.Same here on 14.0.1, updated to 14.0.4 and it worked again!
Happened to me on 14.0.1 but seems to be fixed by upgrading to 14.0.4
Will update if it occurs again 👀
We have the same issue with dynamic routes; right now we are on
v13.5.6, but our dev environment is onv14.0.3. We are going to update the dev tov14.0.4, sadly it will take some time to go into production, but hopefully the error will be resolved. Will report back.Upgrading to latest version doesnt works for me, on production it still sends empty responce with 304 status.
revalidatewill work together withexport const dynamic = 'force-static'. I meant that it helped me because I have a static site that does not require revalidation.Hi, I have the same problem. Since this impacts all the site pages, it is a blocker for moving into production. I hope there will be a solution, perhaps a fix to detect this condition and regenerate the page?
I have the same problem, and my project is facing issues and has come to a complete halt. I hope the members resolve the issue in Next.
We encountered this issue as well on a self hosted NextJs project. Switching back to
13.4.19was indeed the solution for now.@syed-ahmad Our code looks very similar and we encountered the same issue. when we built our docker image and ran it locally we could even reproduce the error.
We just had to leave it running a bit (presumably when next.js cache revalidates) and eventually we got back blank pages with
304 Not Modified.For now we have removed generateStaticParams from our dynamic route.