Routes using data fetching methods return 304 on non-conditional requests
Problem
Link to the code that reproduces this issue https://github.com/kevineinarsson/next-revalidate-issue To Reproduce 1. Start the application in production mode (build & start) 2. Curl one of the routes: [code block] 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 }`) [code block] 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 - [X] I verified that the issue exists in the latest Next.js canary release Provide environment information [code block] 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. <sub>NEXT-1699</sub>
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Routes using data fetching methods return 304 on non-conditional requests
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 inst
Trust Score
6 verifications
- 1
We ran into the same issue (13.5.1 with app folder on production and self-hosted
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.
- 2
As a workaround we resorted to using `export const dynamic = 'force-dynamic';` o
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.
Validation
Resolved in vercel/next.js GitHub issue #56018. Community reactions: 13 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep