opennextjs / opennextjs-netlify

Open Next.js adapter for Netlify
https://opennext.js.org/netlify
678 stars 87 forks source link

[Bug]: ISR not working as expected #1028

Closed caleblawrence closed 2 years ago

caleblawrence commented 2 years ago

Summary

I can't get ISR to work with Netlify even though it's working on Vercel and locally. Example page:

import React from "react";

const ISRTest = ({ time }) => {

  return (
      <div style={{margin: 50}}>
            <p style={{fontSize: 30}}>{time}</p>
      </div>
  );
};

export async function getStaticProps() {
  const currentTime = new Date()
  currentTime.toLocaleString('en-US', { timeZone: 'America/New_York' })

  console.log("currentTime", currentTime);
  return {
    props: {
      time: currentTime.toLocaleTimeString(),
    },
    revalidate: 60,
  };
}

export default ISRTest;

If I look at the function logs for Function ___netlify-odb-handler I see:

9:24:34 AM: 27fd4a59 INFO   currentTime 3:24:34 PM

And this log appears every 60 seconds when I refresh the page like I would expect however the page never changes from the time when it was deployed (cache is never refreshed?).

Steps to reproduce

See summary

A link to a reproduction repository

No response

Plugin version

4.1.0

More information about your build

What OS are you using?

Mac OS

Your netlify.toml file

[build] publish = ".next"

[[plugins]] package = "@netlify/plugin-nextjs"

Your public/_redirects file

`_redirects` ```toml # Paste content of your `_redirects` file here ```

Your next.config.js file

module.exports = { reactStrictMode: true, images: { domains: ["imgurl.com"], }, };

Builds logs (or link to your logs)

Build logs ``` # Paste logs here ```

Function logs

Function logs ``` # Paste logs here ```

.next JSON files

generated .next JSON files ``` # Paste file contents here. Please check there isn't any private info in them # You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time. ```
caleblawrence commented 2 years ago

This is really odd - it did end up updating when I checked 30 minutes later. But it seemed to take a very long time. Even though I see it's running getStaticProps from the function log it does not update the page when I go refresh it again.

caleblawrence commented 2 years ago

Everyone once in a while I see it going back to really old version of the cache as well.

ascorbic commented 2 years ago

Hi. Can you share a link please?

caleblawrence commented 2 years ago

Here is the repo: https://github.com/caleblawrence/isr-bug-example Vercel site: https://isr-bug-example.vercel.app/ Netlify site: https://elegant-brown-75e87c.netlify.app/

ascorbic commented 2 years ago

Thanks for the excellent repro! This is a bug, and I will have a fix out today. In the meantime you can work around it by setting the env var EXPERIMENTAL_ODB_TTL to true and rebuilding.

caleblawrence commented 2 years ago

Thank you! you guys are on it :)

ascorbic commented 2 years ago

This is released in version 4.4.1 of the build plugin. Can you confirm the fix works for you?

caleblawrence commented 2 years ago

you mean 4.1.1 right @ascorbic? From what I'm seeing it still takes quite a bit (5 minutes maybe) to clear out the stale cache and refresh it with the new data from getStaticProps. I see in the logs that getStaticProps is running and generating a new time but it doesn't show up on the page for a while.

I'm double checking right now and I'm going to update and re-deploy the example solution just to make sure.

caleblawrence commented 2 years ago

Yeah I confirmed the updated time still comes in a 2-5 minutes later than then getStaticProps is run. That's not all that bad I suppose it's just a bit unexpected. In Vercel I can literally hit CMD + R twice in a row and I'll see the new page (assuming getStaticProps runs pretty fast like it does here). Updated example app: https://elegant-brown-75e87c.netlify.app/ Repo: https://github.com/caleblawrence/isr-bug-example

ascorbic commented 2 years ago

Hi @caleblawrence , Yes, 4.1.1. Generally you should expect the updated content to be visible within 1 minute. It runs immediately, and requests from new CDN nodes will get the new data as soon as it's available (so within a second or so), but the node that made the revalidate request will have to wait til the stale content expires, which is up to 60 seconds. This optimises for real life performance by allowing more to be cached at the edge, though it does mean you don't get the ability to reload and see the new content immediately. More details are here: https://github.com/netlify/netlify-plugin-nextjs/blob/main/docs/isr.md

caleblawrence commented 2 years ago

Got it. Ok cool thank you sir.