Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On-Demand Revalidation does not revalidate when using the App Router and deployed to Vercel #50714

Closed
1 task done
austintreneff opened this issue Jun 2, 2023 · 33 comments
Closed
1 task done
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@austintreneff
Copy link

Verify canary release

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

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.15.0
      npm: 9.5.0
      Yarn: 1.22.19
      pnpm: 8.5.1
    Relevant packages:
      next: 13.4.5-canary.4
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/austintreneff/reproduction-app-revalidate

To Reproduce

  1. Clone or manually copy the minimal reproduction created here
  2. Deploy the project to Vercel (this is necessary because while running locally the issue does NOT exist)
  3. Once deployed, navigate to the home page where you will see a Date (generate at build time) and a random number (fetched at build time)
  4. To perform an "On-demand revalidation" navigate to the path /api/revalidate
  5. You should see a 200 response confirming the validation
  6. Navigate back to the home page and notice that the content has not be revalidated

Describe the Bug

When deployed to Vercel, On-demand Revalidation using the App Router and revalidatePath does not revalidate data on static paths.

When running the project locally, the revalidation correctly updates the data, but once deployed to Vercel, the data never gets updated. I have confirmed everything works fine when running locally with next build && next start

Expected Behavior

I expect the data revalidation to successfully revalidate the home page of the app.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

@austintreneff austintreneff added the bug Issue was opened via the bug report template. label Jun 2, 2023
@github-actions github-actions bot added area: app App directory (appDir: true) Runtime Related to Node.js or Edge Runtime with Next.js. labels Jun 2, 2023
@hiddenest
Copy link
Contributor

I'm experiencing a similar issue, and both revalidatePath and revalidateTag don't seem to be working in v13.4.5-canary.4.

@agallio
Copy link

agallio commented Jun 3, 2023

I have the same issue. When running locally using pnpm build && pnpm start the revalidatePath is working, but when deployed to Vercel, it's not working. Next.js v13.4.4

@hiddenest
Copy link
Contributor

similar issue: #49861

btw, I just opened a Vercel support ticket. because it suddenly doesn't worked for me from June 2.
so, it could be related to Vercel platform itself, not the problem of Next.js. 🤔

@roysabenecio
Copy link

Debug info:

  • error rendering: Error: Invariant: static generation store missing in revalidateTag /students

This appears when running npm run dev with turbo. It works fine without turbo, though in an npm run build it doesnt work

@bmarianome
Copy link

Is there any workaround? Is it working in any previous version?

@MaxiSantos
Copy link

may this issue be related with this feature being billed? https://vercel.com/docs/infrastructure/data-cache/limits-and-pricing#usage

@hiddenest
Copy link
Contributor

another similar issue: #49387

@austintreneff
Copy link
Author

may this issue be related with this feature being billed? https://vercel.com/docs/infrastructure/data-cache/limits-and-pricing#usage

@MaxiSantos I don't believe so. Hobby/Free accounts are allowed 100/validations per account according to the docs.

@austintreneff
Copy link
Author

Is there any workaround? Is it working in any previous version?

@marianobenitezz I haven't found a direct workaround to the issue, but for my use case I was able to implement Draft Mode on my staging instance. Of course this is not a great solution for production environments.

@swarnava
Copy link
Member

Hi,

We have recently pushed couple of ISR related fix in Next.js version 13.4.5. Could you try and let us know how it goes?

@BradleyBurgess1
Copy link

BradleyBurgess1 commented Jun 12, 2023

Hi,

We have recently pushed couple of ISR related fix in Next.js version 13.4.5. Could you try and let us know how it goes?

It still doesn't appear to be working, tested with revalidatePath on v13.4.5 and deployed on Vercel. It is worth noting that this does work locally with next build and next start.

@hiddenest
Copy link
Contributor

Hi,

We have recently pushed couple of ISR related fix in Next.js version 13.4.5. Could you try and let us know how it goes?

I've also tried updating to v13.4.5, but it doesn't seem to be working.

@swarnava
Copy link
Member

Thank you! We will investigate this separately and report back!

@nabildroid
Copy link

here is a link for a reproducible issue https://codesandbox.io/p/sandbox/next-js-fxis37
in dev mode it works (you can revalidate) but in production the page /post/hello never get revalidated (i tried all possible combination of https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config)

@kubamus
Copy link

kubamus commented Jun 22, 2023

There is also this bug on netlify, so it's not Vercel's fault. The weird thing is that it works on local machines but not on hosting

@theDanielJLewis
Copy link

I get this on some revalidation attempts and not on others (local and deployed to a private server). I'm not sure what makes them different, but it doesn't seem to be 100% reproducible for me.

@theDanielJLewis
Copy link

Would route groups have any effect on this? Like if my filesystem path is actually (memberPages)/items/(mainLayout)/[id]/settings/page.tsx, should the path be that, or simply /items/[id]/settings?

@h-jennings
Copy link

In my case, it turned out that I wasn't passing the native fetch function to my graphql client. I thought this library already used fetch, but perhaps there's a difference between them in Next.js-land. Adding this line fixed the issue and revalidateTag worked as expected.

@theDanielJLewis
Copy link

theDanielJLewis commented Jun 28, 2023

I'm working with data pulled directly from the database. On a settings page, for example, I have a button that auto-updates some information and saves that to the database. The page looks fine and the data saves, but if they navigate away from that page and click back to it, the page will show the old data.

So this is where I thought I could use revalidatePath('/items/UNIQUE_ID/settings') (where UNIQUE_ID is either the item's object ID string, or even [id] as the documentation says to use—but it's frustrating that I can't invalidate only a single page). I would have expected this would let me invalidate the cache of only that one page, or even the path. But nope, it gives me that same error:

Invariant: static generation store missing in revalidateTag

@nabildroid
Copy link

you can use revalidateTag to revalidate a specific Ids

@theDanielJLewis
Copy link

@nabildroid, I'm pulling data directly from my DB via external functions. I'm not using Fetch. Thus, it appears from the documentation that tags won't work for me since they only work on Fetch.

@elie222
Copy link

elie222 commented Jul 7, 2023

@nabildroid, I'm pulling data directly from my DB via external functions. I'm not using Fetch. Thus, it appears from the documentation that tags won't work for me since they only work on Fetch.

You can use unstable_cache to make it work, but ya..

@nabildroid
Copy link

There's a hacky way to still achieve it, just fetch 65base image

@elisaado
Copy link

@nabildroid what do you mean with 65base image?

@nabildroid
Copy link

Fetch something like this
data:image/jpeg;base64, LzlqLzRBQ... '

@palmamartin
Copy link

Any update on this? It seems revalidateTag and revalidatePath is still not working on Vercel. On a local build everything works as expected.
Moreover when I tag my fetches for a relative big site the Vercel builds never ends and after 15 minutes it gets killed by Vercel.

@leerob
Copy link
Member

leerob commented Jul 26, 2023

Any update on this? It seems revalidateTag and revalidatePath is still not working on Vercel.

@palmamartin We will need more specific information for what you're seeing exactly and a reproduction. These functions are working correctly in production for our website, as well as other demo sites and tests. That doesn't mean there might be a bug, but it's hard to say unless there's specific details.

Moreover when I tag my fetches for a relative big site the Vercel builds never ends and after 15 minutes it gets killed by Vercel.

My assumption here is that it doesn't have anything to do with tagging fetches, but if you are trying to generate a large site, are you trying to build many static pages? How long does it take to run next build locally? Can you run vercel build locally to validate?

@leerob leerob added the please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity label Jul 26, 2023
@github-actions
Copy link
Contributor

Please verify that your issue can be recreated with next@canary.

Why was this issue marked with the please verify canary label?

We noticed the provided reproduction was using an older version of Next.js, instead of canary.

The canary version of Next.js ships daily and includes all features and fixes that have not been released to the stable version yet. You can think of canary as a public beta. Some issues may already be fixed in the canary version, so please verify that your issue reproduces by running npm install next@canary and test it in your project, using your reproduction steps.

If the issue does not reproduce with the canary version, then it has already been fixed and this issue can be closed.

How can I quickly verify if my issue has been fixed in canary?

The safest way is to install next@canary in your project and test it, but you can also search through closed Next.js issues for duplicates or check the Next.js releases. You can also use the GitHub templates (preferred) for pages and App Router, or the CodeSandbox: pages or CodeSandbox: App Router templates to create a reproduction with canary from scratch.

My issue has been open for a long time, why do I need to verify canary now?

Next.js does not backport bug fixes to older versions of Next.js. Instead, we are trying to introduce only a minimal amount of breaking changes between major releases.

What happens if I don't verify against the canary version of Next.js?

An issue with the please verify canary that receives no meaningful activity (e.g. new comments that acknowledge verification against canary) will be automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue, with the required reproduction, using next@canary.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the 👍 reaction on the topmost comment (please do not comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren't you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

@palmamartin
Copy link

Hey @leerob, what we noticed is that revalidateTag and revalidatePath do not work on Vercel preview/development builds. On a production build of the same site it works as expected. Can that be? If that is the case and not a bug it would be nice to note that in the docs.

My assumption here is that it doesn't have anything to do with tagging fetches, but if you are trying to generate a large site, are you trying to build many static pages?

Around 111 static pages. Here the times for building it locally:

  • next build: 13s
  • vercel build: 26s

We currently tag the each individual static page using the following schema: "/<locale>/<slug>" e.g. ("/it/publ/bilanciare-gli-interessi-scientifici-e-i-diritti-dei-partecipanti-e-delle-parteci"), so they can becoming quite long. Is there any limit on the length of a cache tag?

Just retried enabling tags and the build still keeps running until it gets killed by Vercel. The project code is private so I cannot share it publicly unfortunately. But here is the build log of Vercel:

[09:23:34.606] Running build in Cleveland, USA (East) – cle1
[09:23:34.666] Cloning github.com/****** (Branch: feat/ondemandrevalidation, Commit: fa4a442)
[09:23:35.329] Cloning completed: 662.52ms
[09:23:39.147] Restored build cache
[09:23:39.172] Running "vercel build"
[09:23:39.636] Vercel CLI 31.1.1
[09:23:39.909] Installing dependencies...
[09:23:40.161] yarn install v1.22.17
[09:23:40.225] [1/4] Resolving packages...
[09:23:40.432] success Already up-to-date.
[09:23:40.440] Done in 0.28s.
[09:23:40.451] Detected Next.js version: 13.4.12
[09:23:40.452] Running "yarn run build"
[09:23:40.615] yarn run v1.22.17
[09:23:40.641] $ next build
[09:23:41.170] - info Creating an optimized production build...
[09:23:54.637] - info Compiled successfully
[09:23:54.638] - info Linting and checking validity of types...
[09:24:01.466] - info Collecting page data...
[09:24:02.421] - info Generating static pages (0/111)
[09:24:02.549] - warn 
[09:24:02.549] metadata.metadataBase is not set for resolving social open graph or twitter images, using "https://******.vercel.app". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase
[09:24:09.710] - info Generating static pages (27/111)
[09:24:14.830] - warn 
[09:24:14.830] metadata.metadataBase is not set for resolving social open graph or twitter images, using "https://******.vercel.app". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase
[09:24:15.405] - info Generating static pages (55/111)
[09:24:15.535] - warn 
[09:24:15.535] metadata.metadataBase is not set for resolving social open graph or twitter images, using "https://******.vercel.app". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase
[09:24:16.042] - info Generating static pages (83/111)
[09:24:17.665] - info Generating static pages (111/111)
[09:24:17.689] - info Finalizing page optimization...
[09:24:17.693] 
[09:24:17.738] Route (app)                                                                                                                                             Size     First Load JS
[09:24:17.738] ┌ ● /[lang]                                                                                                                                             1.23 kB         145 kB
[09:24:17.738] ├   ├ /it
[09:24:17.738] ├   └ /de
[09:24:17.738] ├ ● /[lang]/[...slug]                                                                                                                                   2.64 kB         161 kB
[09:24:17.738] ├   ├ /it/chris
[09:24:17.738] ├   ├ /it/partecipare
[09:24:17.738] ├   ├ /it/ricerca
[09:24:17.738] ├   └ [+69 more paths]
[09:24:17.738] ├ ● /[lang]/glos                                                                                                                                        1.69 kB         161 kB
[09:24:17.738] ├   ├ /it/glos
[09:24:17.738] ├   └ /de/glos
[09:24:17.738] ├ ● /[lang]/publ                                                                                                                                        208 B           118 kB
[09:24:17.738] ├   ├ /it/publ
[09:24:17.738] ├   └ /de/publ
[09:24:17.738] ├ ● /[lang]/publ/[slug]                                                                                                                                 1.68 kB         161 kB
[09:24:17.738] ├   ├ /it/publ/the-dynamic-consent-of-the-cooperative-health-research-in-south-tyrol-chris-study-broad-aim-within-specific-oversight-and-communication
[09:24:17.738] ├   ├ /it/publ/bilanciare-gli-interessi-scientifici-e-i-diritti-dei-partecipanti-e-delle-parteci
[09:24:17.738] ├   ├ /it/publ/metaboliti-correlati-a-eta-sesso-indice-di-massa-corporea-dieta-e-menopausa-in-un
[09:24:17.738] ├   └ [+11 more paths]
[09:24:17.739] ├ ● /[lang]/publ/area/[[...slug]]                                                                                                                       439 B           118 kB
[09:24:17.739] ├   ├ /it/publ/area/area-cardiovascolare
[09:24:17.739] ├   ├ /it/publ/area/area-neurologica
[09:24:17.739] ├   ├ /it/publ/area/area-metabolica
[09:24:17.739] ├   └ [+3 more paths]
[09:24:17.739] ├ ● /[lang]/studies                                                                                                                                     1.03 kB         144 kB
[09:24:17.739] ├   ├ /it/studies
[09:24:17.739] ├   └ /de/studies
[09:24:17.739] ├ ● /[lang]/studies/[slug]                                                                                                                              1.68 kB         161 kB
[09:24:17.739] ├   ├ /it/studies/chris-covid
[09:24:17.739] ├   └ /de/studies/chris-covid-19-studie
[09:24:17.739] ├ λ /api/draft                                                                                                                                          0 B                0 B
[09:24:17.739] ├ λ /api/revalidate                                                                                                                                     0 B                0 B
[09:24:17.739] ├ ○ /api/search/index/de                                                                                                                                0 B                0 B
[09:24:17.739] ├ ○ /api/search/index/it                                                                                                                                0 B                0 B
[09:24:17.739] ├ ○ /opengraph-image.png                                                                                                                                0 B                0 B
[09:24:17.739] ├ ○ /robots.txt                                                                                                                                         0 B                0 B
[09:24:17.739] └ ○ /twitter-image.png                                                                                                                                  0 B                0 B
[09:24:17.739] + First Load JS shared by all                                                                                                                           83.9 kB
[09:24:17.739]   ├ chunks/596-518a7f984d7286cd.js                                                                                                                      25.7 kB
[09:24:17.739]   ├ chunks/685-10c137faf4976044.js                                                                                                                      5.85 kB
[09:24:17.739]   ├ chunks/fd9d1056-8f15590ce1a1af90.js                                                                                                                 50.5 kB
[09:24:17.739]   ├ chunks/main-app-a6af1440834f9c4a.js                                                                                                                 214 B
[09:24:17.739]   └ chunks/webpack-1a5ffed7cf9d7923.js                                                                                                                  1.67 kB
[09:24:17.739] 
[09:24:17.740] Route (pages)                                                                                                                                           Size     First Load JS
[09:24:17.740] ─ ○ /404                                                                                                                                                182 B          75.8 kB
[09:24:17.740] + First Load JS shared by all                                                                                                                           75.6 kB
[09:24:17.741]   ├ chunks/framework-8883d1e9be70c3da.js                                                                                                                45 kB
[09:24:17.741]   ├ chunks/main-7854705116f5d0d8.js                                                                                                                     28.7 kB
[09:24:17.741]   ├ chunks/pages/_app-52924524f99094ab.js                                                                                                               195 B
[09:24:17.741]   └ chunks/webpack-1a5ffed7cf9d7923.js                                                                                                                  1.67 kB
[09:24:17.741] 
[09:24:17.741] ƒ Middleware                                                                                                                                            44.9 kB
[09:24:17.741] 
[09:24:17.741] λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
[09:24:17.741] ○  (Static)  automatically rendered as static HTML (uses no initial props)
[09:24:17.741] ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
[09:24:17.741] 
[09:24:17.829] Done in 37.22s.
[09:24:20.618] Traced Next.js server files in: 2.717s
[09:24:25.437] Created all serverless functions in: 4.817s
[09:24:25.494] Collected static files (public/, static/, .next/static): 5.218ms
[09:24:26.450] Build Completed in /vercel/output [47s]
[09:24:26.822] Deploying outputs...
[09:24:26.822] Injecting preview comments into the build output, you can disable this in your project settings.

@typeofweb
Copy link
Contributor

I believe that either the documentation is wrong or there's a bug in Next.js. Implicit tags saved in incremental cache store are actually referring to the routes, not pathnames, and therefore you should be calling revalidatePath("/page") instead of just revalidatePath("/")

@balazsorban44
Copy link
Member

This issue has been automatically closed because it wasn't verified against next@canary. If you think it was closed by accident, please leave a comment. If you are running into a similar issue, please open a new issue with a reproduction. Thank you.

@nikravi
Copy link

nikravi commented Sep 4, 2023

I used canary 13.4.20-canary.15 and revalidatePath is not working locally

@github-actions
Copy link
Contributor

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 github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests