Next.js shows old data even though fetch uses cache: 'no-store'
fetch(url, { cache: 'no-store' }) returns the same data after the source changedShort answer
A fetch with cache: 'no-store' is re-fetched on every request, so stale data means something else decides. Check four things in order: a route segment config such as fetchCache or dynamic that overrides the option, data that is not read through fetch at all, a conflicting revalidate option, and in development the HMR cache.
Fix it fast
1Find out which cause you have
Turn on fetch logging in development. It prints every fetch with a cache hit or miss, which shows whether the request is cached at all or whether the page itself is prerendered.
// next.config.ts const nextConfig = { logging: { fetches: { fullUrl: true } }, } export default nextConfig2Match what you see, then jump to its fix
- 1
Your fetch says no-store, but the page or a parent layout exports fetchCache or dynamicA segment config overrides the fetch optionFix - 2
The data comes from an ORM, a database driver or an SDK, and the page is prerendered at build timeThe data is not read through fetchFix - 3
A warning in the dev terminal about conflicting options on a fetchConflicting cache and revalidate options on one fetchFix - 4
Fresh data after a full page reload, stale data after saving a fileOnly in development: the HMR cacheFix
- 1
What does the error look like?
fetch(url, { cache: 'no-store' }) returns the same data after the source changedPage shows old data in production but fresh data after a restartFresh data on full reload but not after saving a file in next dev
Cause 1 of 4
A segment config overrides the fetch option
1Check
Search the route's page, layout and route files for exported segment options. fetchCache = 'force-cache' sets the cache option of every fetch in that segment to force-cache, and dynamic = 'force-static' or 'error' prerenders the route.
grep -rn "export const \(fetchCache\|dynamic\|revalidate\)" app/2Fix
Remove the option, or set the one you mean. For a page that must be fresh on every request, force dynamic rendering for that segment.
// page.tsx or layout.tsx
export const dynamic = 'force-dynamic'3Verify
Build and start the production server, change the source data, reload the page twice.
npm run build && npm run startConfirmed by nextjs.org
Cause 2 of 4
The data is not read through fetch
1Check
The fetch cache options only apply to fetch. A route with no Request-time API and no uncached fetch is prerendered during next build, so its data is frozen into the build.
npm run build
# then read the route list the build prints for your page2Fix
Opt the route out of prerendering. Force dynamic rendering, or cache the function on purpose with unstable_cache and a revalidate time.
import { unstable_cache } from 'next/cache'
export const getPosts = unstable_cache(
async () => db.select().from(posts),
['posts'],
{ revalidate: 60 }
)3Verify
After the change, update a row in the database and confirm the page shows it within the time you set, or at once with force-dynamic.
npm run build && npm run startConfirmed by nextjs.org
Cause 3 of 4
Conflicting cache and revalidate options on one fetch
1Check
Look for a fetch that sets both next.revalidate with a number and cache: 'no-store'. Next.js ignores both when they conflict.
grep -rn "no-store" app/ lib/ | grep revalidate2Fix
Keep one of them. Use cache: 'no-store' for always fresh, or next.revalidate for a time limit.
const res = await fetch(url, { cache: 'no-store' })
// or
const res2 = await fetch(url, { next: { revalidate: 60 } })3Verify
Restart next dev and confirm the warning is gone.
npm run devConfirmed by nextjs.org
Cause 4 of 4
Only in development: the HMR cache
1Check
In next dev, Server Component fetch responses are kept across hot module replacement refreshes, including no-store requests. Navigation or a full reload clears them.
grep -n "serverComponentsHmrCache" next.config.*2Fix
Reload the page fully, or switch the experimental cache off in the config.
// next.config.ts
const nextConfig = {
experimental: { serverComponentsHmrCache: false },
}
export default nextConfig3Verify
Restart next dev, edit a file and watch the data change on the next refresh.
npm run devConfirmed by nextjs.org
How do I stop it coming back?
- Test caching behaviour with next build and next start, not only next dev.
- Set one caching rule per route and put it where the next reader will look, at the top of the page file.
- Keep logging.fetches on in development so cache hits are visible.
- Use cache: 'force-cache' or next.revalidate only on data you are happy to serve old.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
TypeError: fetch failed in a Next.js Server Component or route handler
TypeError: fetch failed
TypeError: fetch failed is a wrapper.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fixWeb apps
Firebase Auth says the API key is not valid
Firebase: Error (auth/api-key-not-valid.-please-pass-a-valid-api-key.)
The apiKey your app sends is either empty, wrong, or blocked.
4 causes, each with a fix