Fetch cache seeded at build time during SSG is not reused at runtime on Vercel
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/Fredkiss3/inconsistent-fetch-cache-during-build-and-start
To Reproduce
- Import the project on vercel
- Watch the build logs, it should give you the same logs for every page as they are SSG'ed (which means the data is cached)
{
'LAYOUT FETCH': {
unixtime: 1708398669,
utc_datetime: '2024-02-20T03:11:09.078181+00:00'
}
}
- When the build has finished, go to
/u/5 - You will notice that the data shown is different than the data shown at build time
- If you go to
/u/3it will show a different value (the same that is shown at build time)
Current vs. Expected behavior
Following the previous steps, I expected to have the same values shown at build time and at runtime, meaning that the fetch cache is set and reused at runtime but it doesn't.
If you try building the project locally, you will notice that the data is effectively cached at build time and the same data is reused at runtime. This may be because when running locally nextjs use the folder .next/cache/fetch-cache and is correctly seeded at build time, On vercel it isn't considered.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:00 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6020
Binaries:
Node: 20.11.1
npm: 10.2.4
Yarn: N/A
pnpm: 8.15.3
Relevant Packages:
next: 14.1.0
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)
App Router, Data fetching (gS(S)P, getInitialProps)
Which stage(s) are affected? (Select all that apply)
Vercel (Deployed)
Additional context
The site is deployed on Vercel.
Also If you have access to Vercel Request metrics, you will notice that the first call to the fetch cache shows a CACHE MISS and next requests reuse the cached data :
First Request
Second Request
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction repository and compare the local .next/cache/fetch-cache behavior with the Vercel build logs and first runtime request. Inspect how the App Router data-fetching cache is seeded during SSG and made available after deployment; done means runtime requests reuse the values generated at build time on Vercel.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs, react
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100