Skip to content

Revalidate doesn't work always with Netlify Functions #321

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

Closed
saidattax opened this issue May 18, 2021 · 7 comments
Closed

Revalidate doesn't work always with Netlify Functions #321

saidattax opened this issue May 18, 2021 · 7 comments
Labels
duplicate This issue or pull request already exists

Comments

@saidattax
Copy link

Describe the bug
I have a page which has an option revalidate: 5,. It works fine with netlify dev. However, when I deploy it and run on netlify, the serverless functions are not being triggered on refresh after 5 seconds.

I made a small test using codesanbox server and a next js site which shows the current time. The time is calculated on the server and sent to the next js app which is handled using getStaticProps. There's also a couple of routes sent via the server to getStaticPaths

To Reproduce
Steps to reproduce the behavior:

  1. Go to Codesandbox Server (required)
  2. Go to https://goofy-galileo-ba9249.netlify.app/
  3. Refresh
  4. If it works, refresh again
  5. Time does not update after 5 seconds between refreshes

Link to Github Repo: https://github.com/saidattax/next-js-test

Expected behavior
Everytime on refresh, atleast after 5 seconds, the serverless function should trigger to get the latest getStaticProps

Versions

  • Next.js: 10.2.0
  • plugin (if installed at fixed version): 3.3.0

If you're using the CLI to build

  • OS: [e.g. macOS, Windows]
  • netlify/cli version:

If you're using file-based installation

  • netlify.toml:
[build]
  command = "npm run build"
  functions = "netlify/functions"
  publish = "out"

[context.production.environment]
  NEXT_SERVERLESS = "true"
  NODE_ENV = "production"

[[plugins]]
  package = "@netlify/plugin-nextjs"
@lindsaylevine lindsaylevine added the duplicate This issue or pull request already exists label May 18, 2021
@lindsaylevine
Copy link

@saidattax hey! thank you so much for opening such a wonderful and detailed issue. we really appreciate the time and thoughtfulness you spent. unfortunately this has been a request/known issue on the platform for nearly a year 😲 (see #151). this is netlify's most recent work to address this issue: #151 (comment). for this reason, i'll close your issue, but feel free to direct any additional comments/feedback to #151!! ❤️

@saidattax
Copy link
Author

saidattax commented May 18, 2021

Hey @lindsaylevine ! Thanks for getting back. However, I have another project where I use the same revalidate and the netlify function is indeed called on every request within 5 seconds.

It can also be seen in it's function next_pname logs, that it works.

Here's the deploy id 609e5727d93f45bc37e4e932 for that project.

Any idea how it's working there but not in this one? Did I do something there that I missed here?

Thanks

@saidattax
Copy link
Author

saidattax commented May 18, 2021

@lindsaylevine

Also, a different issue I found,

In my package.json I have fixed the version of the plugin

    "devDependencies": {
        "@netlify/plugin-nextjs": "3.2.2"
    }

But in the build, it is taking the latest version? 🤔

4:28:33 PM: ❯ Installing plugins
4:28:33 PM:    - @netlify/plugin-nextjs@3.3.0
4:28:54 PM: ​
4:28:54 PM: ❯ Loading plugins
4:28:54 PM:    - @netlify/plugin-nextjs@3.3.0 from netlify.toml

Here's the deploy id 60a39dbfcd1460de0e4c6613

This is supposed to say Installing plugins @netlify/plugin-nextjs@3.2.2 , right?

@lindsaylevine
Copy link

lindsaylevine commented May 18, 2021

@saidattax

  1. i think what you're describing is just SSR, aka what we do in place of ISR. if a next project has revalidate set, we simply SSR that page instead of the prerendered html.

  2. you'd need to install it as a prod dependency, not a dev dep! i just checked our README and realized we have -D in there so lemme go replace that rn! (see https://github.com/netlify/netlify-plugin-nextjs#faq though fyi!)

@lindsaylevine
Copy link

ok, i see now. your site in the original issue body is not updating. this is because, i believe, you're using fallback: true, which means (as of the most recent plugin version) we cache the first function response. if you take that out, it should work as you expect.

@saidattax
Copy link
Author

Thank you so much for the help @lindsaylevine ! That fixes it :)

@lindsaylevine
Copy link

yay!! happy to help ❤️ :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants