You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See that the revalidate caching & unstable_cache does not work locally at all (it will show "loading" on each reload)
When deployed to vercel - https://cache-bug-five.vercel.app/ see that it never shows "loading" at all, and stale data is shown after 5 seconds (stale-while-revalidate is never skipped)
Current vs. Expected behavior
There are three aspects to this issue: dev and prod being behaving differently, caching not working locally, and stale data being returned in prod
Caching in local dev:
Expected: cache works locally for next: revalidate and unstable cache
Current: It does not cache locally at all in dev mode, always showing "loading" in suspense
Caching in prod / skipping stale while revalidate:
Expected: I would expect in prod when using unstable_cache that when the cache has expired, it would not show stale data, but show "loading" and fetch fresh data
Current: it shows stale data
I want to:
Fetch data from an endpoint in a server component
Use suspense to show "loading" when fetching (streaming)
then cache the fetched data (for 5 seconds in this issue example)
if a user visits in under 5 seconds - show stale data
after 5 seconds do not show stale data, show loading and refetch fresh data
and this work in both dev and prod
This is my unstable_cache component:
import{unstable_cache}from'next/cache'constdelay=(ms: number)=>newPromise(resolve=>setTimeout(resolve,ms))constcurrentReadableTime=()=>{constnow=newDate()returnnow.toLocaleTimeString()}consturl='https://jsonplaceholder.typicode.com/posts/1'constgetPosts=unstable_cache(async()=>{constres=awaitfetch(url)constdata=awaitres.json()awaitdelay(2000)return{time: currentReadableTime(),post: data,}},['temperature-data'],// Cache key{revalidate: 5,tags: ['temperature']}// Expire after 5 seconds)exportconstPostUnstable=async()=>{const{ post, time }=awaitgetPosts()return(<div><p>post:</p><div>{time}</div><div>{JSON.stringify(post)}</div></div>)}
Note: I have another component that uses next:revalidate, but this is currently behaving the same way as the unstable cache component.
Prod always shows stale data on new visit (I visited at 58 mins past):
Locally caching does not work, every reload shows suspense "loading":
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
Available memory (MB): 16384
Available CPU cores: 10
Binaries:
Node: 23.11.0
npm: 10.9.2
Yarn: N/A
pnpm: 9.7.0
Relevant Packages:
next: 15.3.2 // Latest available version is detected (15.3.2).
eslint-config-next: 15.3.1
react: 19.1.0
react-dom: 19.1.0
typescript: 5.8.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Use Cache
Which stage(s) are affected? (Select all that apply)
next dev (local), Vercel (Deployed)
Additional context
No response
The text was updated successfully, but these errors were encountered:
AshConnolly
changed the title
Caching not working locally (revalidate and unstable_cache). And cannot avoid stale cache data in prod.
Caching not working locally (revalidate and unstable_cache) and cannot avoid stale cache data in prod.
May 16, 2025
Uh oh!
There was an error while loading. Please reload this page.
Link to the code that reproduces this issue
https://github.com/AshConnolly/cache-bug
To Reproduce
Current vs. Expected behavior
There are three aspects to this issue: dev and prod being behaving differently, caching not working locally, and stale data being returned in prod
Caching in local dev:
Expected: cache works locally for next: revalidate and unstable cache
Current: It does not cache locally at all in dev mode, always showing "loading" in suspense
Caching in prod / skipping stale while revalidate:
Expected: I would expect in prod when using unstable_cache that when the cache has expired, it would not show stale data, but show "loading" and fetch fresh data
Current: it shows stale data
I want to:
This is my unstable_cache component:
Used like this:
Note: I have another component that uses next:revalidate, but this is currently behaving the same way as the unstable cache component.
Prod always shows stale data on new visit (I visited at 58 mins past):

Locally caching does not work, every reload shows suspense "loading":

Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 Available memory (MB): 16384 Available CPU cores: 10 Binaries: Node: 23.11.0 npm: 10.9.2 Yarn: N/A pnpm: 9.7.0 Relevant Packages: next: 15.3.2 // Latest available version is detected (15.3.2). eslint-config-next: 15.3.1 react: 19.1.0 react-dom: 19.1.0 typescript: 5.8.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Use Cache
Which stage(s) are affected? (Select all that apply)
next dev (local), Vercel (Deployed)
Additional context
No response
The text was updated successfully, but these errors were encountered: