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 doesn't revalidate more than once

See original GitHub issue

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 20.4.0: Thu Apr 22 21:46:41 PDT 2021; root:xnu-7195.101.2~1/RELEASE_ARM64_T8101
    Binaries:
      Node: 14.17.1
      npm: 8.2.0
      Yarn: 1.22.10
      pnpm: N/A
    Relevant packages:
      next: 12.2.4
      eslint-config-next: N/A
      react: 17.0.2
      react-dom: 17.0.2

What browser are you using? (if relevant)

n/a

How are you deploying your application? (if relevant)

n/a

Describe the Bug

On-demand ISR is implemented (on /api/revalidate) and while it does flush the site cache once, hitting the endpoint a second time (or more) does not. This is happening in dev as well as in production. CMS is used to fetch the content and to verify this bug, I have updated the content in between calls to /api/revalidate

Expected Behavior

Cache should be flushed each time with new content from the CMS (via getStaticProps)

Link to reproduction

https://github.com/DTS-STN/Service-Canada-Labs

To Reproduce

  • All pages in the app rely on getStaticProps to send a request to our CMS to get content.
  • There’s a revalidate API handler (/api/revalidate.js) created in our app with the following code:
const REVALIDATION_ROUTES = [
  "/home",
];

export default async function handler(req, res) {
  // Check for secret to confirm this is a valid request
  if (req.query.secret !== process.env.REVALIDATION_TOKEN) {
    return res.status(401).json({ message: "Invalid token" });
  }

  try {
    await Promise.all(REVALIDATION_ROUTES.map((route) => res.revalidate(route)));
    return res.json({ revalidated: true });
  } catch (err) {
    console.log(err);
    return res.status(500).send("Error revalidating");
  }
}
  • There is no revalidate property option declared as part of the getStaticProps for any of the pages

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
balasphilipcommented, Aug 24, 2022

I have a similar case, very much similar to the request above :

  • I host Next.js on-premise;
  • CMS pushes data into DB;
  • Next.js 12.2 statically renders pages (SSG) based on data from the DB;
  • then I use DB change stream events to trigger the Next.js service as soon as CMS pushes new portion of data into DB;
  • as the Next.js service got triggered it pings itself by api/revalidate endpoint;
  • the trick is that we have quite a few pages to re-generate, like 100+, from time to time 200+, so we use similar Promise.all approach.

The result is:

  • no errors from Next.js revalidation API;
  • I see some internal Next.js warning messages like “Warning: data for page “…” is 896 kB which exceeds the threshold of 128 kB” which means the revalidation is processing my page;
  • new updates don’t reflect in a browser

Then I use Postman and trigger api/revalidate explicitly, and the page gets updated in a browser.

Any thoughts on that?

For context: I want to use this feature to update hundreds and maybe thousands of pages in the future.Is it mature enough to rely on it or better to switch to SSR or revalidation with an interval?

Thanks!

0reactions
github-actions[bot]commented, Oct 9, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incremental Static Regeneration - Data Fetching - Next.js
Note: Middleware won't be executed for On-Demand ISR requests. Instead, call revalidate() on the exact path that you want revalidated. For example, if...
Read more >
A Complete Guide To Incremental Static Regeneration (ISR ...
ISR doesn't always make sense for small websites. If your revalidation period is larger than the time it takes to rebuild your entire...
Read more >
On-demand ISR not working - Developing with Prismic
I made a revalidate.js in my api folder with the code below: // pages/api/revalidate.js import * as prismic from '@prismicio/client'; import ...
Read more >
How to Update Static Content in Next.js Automatically with ...
Without ISR and revalidation, here's how content updates: Site builds; User requests site, receives static file; Content updates in headless ...
Read more >
So what is with the revalidation delay in ISR? : r/nextjs - Reddit
ISR delays the first load like SSR (on-demand rendering), then serves ... more money scaling the backend, I increased revalidate time to 360 ......
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