15

I have this NextJS site where there is this getStaticProps that load data from Firestore.

I have this:

return {
    props: {
      allPosts: posts,
    },
    revalidate: 60,
  }

where from what I know will load data from firebase every one minute. However, it doesn't seem to work and data are just not updated.

Is this revalidate an experimental feature? Anyway that I can get it to work? Else I would have to rebuild and export frequently.

Daryl Wong
  • 2,023
  • 5
  • 28
  • 61
  • 2
    It is not experimental, should work fine. `will load data from firebase every one minute` at most every minute, but only after request comes. (stale-while-revalidate strategy https://tools.ietf.org/html/rfc5861). So after minute you need to refresh the page, then next will request new data, and then refresh page again to see changes? – Danila Feb 12 '21 at 07:13
  • @Danila mine is not working and I do not know why – Daryl Wong Feb 12 '21 at 09:36
  • How did you checked that? – Danila Feb 12 '21 at 09:48
  • @Danila, I add new post to firestore database but after a minute or so, it is not shown on my site. But if I ran build and export again, the post is shown. – Daryl Wong Feb 12 '21 at 10:20
  • 2
    So you only exporting static files without running the next server? That is the problem, if you want Incremental Static Regeneration then you need to use `next start`, otherwise how exactly next could generate new files if the sever is not running and you only serving static html and js? – Danila Feb 12 '21 at 10:29
  • This is the command that I used to deploy to firebase: npm run build && npm run export && firebase deploy, maybe there are some configurations that need to be done on the config file before deploying to firebase. – Daryl Wong Feb 12 '21 at 10:39
  • Well, as I just said before, it is not gonna work without server (`next start`). You only deploying static files, but you need to run the server. – Danila Feb 12 '21 at 10:44

1 Answers1

13

If you want Incremental Static Regeneration (basically revalidate flag for getStaticProps) then you need to run Next.js server (next start command), without the server there is nothing that could perform requests, update data and generate new static files.

next export only generates static files once, with the data that was available at the build time.

Danila
  • 15,606
  • 2
  • 35
  • 67
  • 3
    This morning I changed the hosting provider to Vercel and it works right out of the bag. I will just stick to Vercel instead of Firebase hosting for now. – Daryl Wong Feb 13 '21 at 08:26
  • @DarylWong for me as well, since we moved to Vercel cloud platform it started working – Ruslan Korkin Apr 08 '21 at 08:52
  • Vercel is not stating hosting, it spins the server, that's why it works. – Danila Jan 25 '22 at 08:58
  • I am trying this on ec2 instance and I am having issue with revalidate, it's not regenerating pages, I tried on local as well it seems to be not working for ISR – Yalamber Feb 09 '22 at 09:03
  • 7
    I find it absolutely terrifying the number of Next.js questions where people answer or comment "just move to Vercel" or similar and it gets upvoted. Mindblowing. There is no other library in any other language which has such a strong preference for a particular hosting provider. There is zero good reason for this. It is a complete conflation of responsibility. It would be similar to buying a car that can only be serviced by one particular mechanic who may retire at any moment. When the solution to all problems is to host with Vercel, that is vendor lock-in. – Neil Mar 10 '22 at 15:48
  • 1
    I don't know how long Vercel is going to be around for, I don't know whether they're profitable, whether they have good management, whether they're going to wake up tomorrow and decide to start charging $100 and hour to use their services. I do know that with any other technology stack I CHOOSE where I host. I can how on AWS, GCP, IBM, Linode, Heroku, Digital Ocean. I've taken over a Next.js app and I feel scammed. I was told it could be hosted anywhere. Which is technically true but... not practically true. This is literally the 6th time I've seen this now. – Neil Mar 10 '22 at 15:51
  • 2
    @Neil you are wrong, Next.js is not different from let's say Express, it can be hosted anywhere, in any environment which supports Node.js. Next.js can also output static files which can be hosted without Node at all, just through Nginx, for example. Please refrain from such comments until you have some understand what Next.js is and what it can or cannot do. – Danila Mar 10 '22 at 16:11
  • @Danila I didn't say it couldn't. – Neil Mar 10 '22 at 16:28
  • 7
    @Danila you can disagree with my opinion but that doesn't give you a reason to tell me I can't comment. Uncool. – Neil Mar 10 '22 at 16:30