question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

On-demand ISR do not work correctly

See original GitHub issue

Verify canary release

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

Provide environment information

 npx next info
/bin/sh: pnpm: command not found

    Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.14.0
      npm: 8.3.1
      Yarn: 1.22.17
      pnpm: N/A
    Relevant packages:
      next: 12.1.0
      react: 17.0.2
      react-dom: 17.0.2

warn  - Latest canary version not detected, detected: "12.1.0", newest: "12.1.1-canary.16".
        Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
        Read more - https://nextjs.org/docs/messages/opening-an-issue

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

We have a NextJS front end and Sanity.io for the back end. I implement the on-demand ISR API on the /api/revalidate path, which is called whenever Sanity content changed. Before this, we use the time-based ISR, but I have removed that part of the code.

When deploy on Vercel, I tested by modifying the content in Sanity and it works correctly: the API is called and the page is updated, but if I make the next changes within a few minutes or so, the page won’t update, even though the API is called properly in the log without catching any error. This happens most of the time, but not all the time. Sometimes, I try to trigger the API call from Insomnia, the page update again with the latest info. But most of the time, I have to wait a few mins, change the content in Sanity and Publish again for it to work.

If I wait for a few minutes after the first revalidation and call the API again, most of the time, the page is updated correctly. But still, not all the time. I wonder if this has anything to do with the fact that we used time-based revalidation before. Maybe some caching laying around, not sure.

On an addition note, when I test the revalidate API call from Insomnia, for both local prod build or Vercel deployed build, sometimes, it takes a whole minute to resolve the query. So one of the possibility is that Vercel has a timeout config for a function call.

Also another quick note that might help others: we use Next middleware auth to block people from visiting our development page, when I call the revalidation API, it is blocked by the popup therefore only always throw errors. The error message was only Failed to revalidate ${urlPath} and I was only able to fix it by deep-dive into the function. Maybe throwing the error with the actual result of the fetch instead would be more helpful? 😃

Thank you!

Expected Behavior

Whenever the /api/revalidate API call, force update the page content

To Reproduce

image image

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
mavic111commented, Apr 26, 2022

I think I found the problem. When i use sanityClient to fetch the props with useCdn: true. The data is coming from CDN that was cached and not updated. After I change useCdn to false, the props that fetched using GetStaticProps now always up to date.

2reactions
turboninhcommented, May 17, 2022

@rodrigo-arias I see this in production 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

On-demand ISR not working - Developing with Prismic
Hi guys, I am trying to implement on-demand incremental static regeneration into my site. I have followed the article here.
Read more >
Why my On-demand ISR in Nextjs is not working?
I'm revalidating this page in the pages/api/revalidate.js file. But I receive the next error: Error: Failed to revalidate ...
Read more >
Incremental Static Regeneration - Data Fetching - Next.js
Note: The experimental-edge runtime is currently not compatible with ISR, although can leverage stale-while-revalidate by setting the cache-control header ...
Read more >
Incremental Static Regeneration – Vercel Docs
Learn how Incremental Static Regeneration works on Vercel and how it provides better performance, increased security, and faster builds.
Read more >
On demand ISR with Next.JS and Sanity - DEV Community ‍ ‍
Static sites are great, right? You get excellent performance and can make the most out of CDNs and... Tagged with nextjs, jamstack, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found