next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Inconsistent revalidate behavior when deployed to Vercel

Open Darkness-2 opened this issue 2 years ago • 2 comments

Link to the code that reproduces this issue

https://github.com/Darkness-2/nextjs-revalidate-bug

To Reproduce

  1. Deploy app to Vercel
  2. Invoke revalidatePath for a path with a short revalidate interval (for example, 60 seconds)
  3. Note the expected behavior is that the next visit to this page will receive a X-Vercel-Cache: REVALIDATED header
  4. However, on occasion you will receive an unexpected X-Vercel-Cache: HIT or X-Vercel-Cache: STALE, and stale data will be served
  5. No matter how many more times the page is hit, the cache does not seem to revalidate until the end of the next revalidate interval

Please note, this does not seem to happen every time, however if you play around with it enough, you will find this behavior. My experience is that this tends to happen very close to when the page is around its revalidation interval (a few seconds before or after the 60 second revalidation period).

I have also tested this locally using npm run build and npm run start, and it works as expected. (Note that when running locally the relevant header is X-Nextjs-Cache)

Note below a reproduction, where I called revalidatePath via a route handler, and the subsequent request for the page's rsc still returned a X-Vercel-Cache: HIT image

Current vs. Expected behavior

Following the steps from the previous section, I expect the next request after a revalidatePath to return a X-Vercel-Cache: REVALIDATED header, along with fresh data.

Instead, a X-Vercel-Cache: HIT or X-Vercel-Cache: STALE header is sometimes returned, along with stale data. The page does not appear to ever be revalidated in these cases, even though revalidatePath was invoked.

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Home
Binaries:
  Node: 18.18.2
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.0.3
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Additional context

I have created an example repo, along with Vercel deployment where it is easy to reproduce the issue, along with instructions for what to look out for.

Github repo Vercel deployment

I also deployed the same project on the canary release to Vercel, and the same issue occurred.

Darkness-2 avatar Nov 29 '23 01:11 Darkness-2

This is really a BIG BIG issue, I'm very scare to publish our app for client to use...

dnguyenfs avatar Dec 18 '23 14:12 dnguyenfs

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

nextjs-bot avatar Jun 15 '25 23:06 nextjs-bot

This issue has been automatically closed due to two years of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!

nextjs-bot avatar Jun 22 '25 23:06 nextjs-bot

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

github-actions[bot] avatar Jul 07 '25 00:07 github-actions[bot]