Fetch requests aren't revalidated properly
TxHawks opened this issue · 0 comments
Link to the code that reproduces this issue
https://github.com/TxHawks/next-revalidate-bug
To Reproduce
- Start the app in development mode and load
localhost:3000
- The server logs will show
cache skip
for the first fetch request in/
andcache-hit
for following three:
GET / 200 in 2802ms
│ GET https://api.restful-api.dev/objects 200 in 880ms (cache skip)
│ │ Cache skipped reason: (cache-control: no-cache (hard refresh))
│ GET https://api.restful-api.dev/objects 200 in 4ms (cache hit)
│ GET https://api.restful-api.dev/objects 200 in 0ms (cache hit)
│ GET https://api.restful-api.dev/objects 200 in 0ms (cache hit)
- Reload the page after waiting several seconds. All fetch requests will now show
cache-hit
.
Current vs. Expected behavior
The reproduction uses a getData
function to fetch data from a single URL four times, with the following request options object:
{
method: "GET",
cache:'force-cache',
next: { revalidate: 1 },
}
My understanding is that the first fetch
request should be a miss
, or a cache skip
, and subsequent requests should be a cache hit
for a single second. In other words, that the cache should be revalidated after one second.
Loading the page for the first time indeed shows this behavior. However, a subsequent load after even several minutes will show a cache hit
for all requests, including the initial one, meaning that the cache was not revalidated as expected.
As an aside, turning on dynamicIO
displays the same behavior, just that each request is sent 3 times, so there are 12 cache hit
s instead of 4.
Another aside, is that my understanding (though I can't find anything about that in the docs) was that calls to fetch
with the same URL have a request-level cache by default, but that is not the case (navigate to /no-cache
and you'll see four cache skip
s). I could find a way to achieve this, other than using revalidateTag
inside after
, which, I don't know, seems wrong and unsafe.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000
Available memory (MB): 65536
Available CPU cores: 10
Binaries:
Node: 20.13.1
npm: 10.5.2
Yarn: 1.22.19
pnpm: 9.12.0
Relevant Packages:
next: 15.1.1-canary.1 // Latest available version is detected (15.1.1-canary.1).
eslint-config-next: N/A
react: 19.0.0
react-dom: 19.0.0
typescript: 5.7.2
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
dynamicIO, Performance, Runtime
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local)
Additional context
No response