Revalidate parameter not working in getStaticProps

I’m trying to make the revalidate option of next.js getStaticProps on Vercel but it doesn’t seem to be working.

Here is how my code looks like (roughly):

export async function getStaticProps() {

  const response = await axios.get(
    `${process.env.API_URL}/endpoint`,
    {
      headers: {
        "Cache-Control": "no-cache, no-store, must-revalidate",
        Pragma: "no-cache",
        Expires: "0",
      },
    }
  );

  return {
    props: {
      response.data
    },
    revalidate: 3600,
  };
}

Even after going to the page multiple times a day it just won’t update. I’m using the free tier btw.

Hi, @lahloumimiahmed11!

Could you create a minimal reproducible example for us to look at?

Hello, thanks for answering. The snippet I provided should be sufficient, I don’t do any additional operation in getStaticProps

Unfortunately, the code snippet alone is not enough to let us debug this with you. There is a lot of project context missing that may interfere with the function you shared.

Past experience tells me that the API endpoint may be part of the problem. The environment variable could be misconfigured or the endpoint might be throwing errors. Using a try/catch statement and console.log() to check the returned data would be a relatively quick way to determine what’s returned from the endpoint. Then you can check the logs for errors.

You can also check the headers for a HIT or MISS that can give you more clues. And you might want to try a shorter time period for revalidate while you’re working out what’s wrong. The example you shared would stick around for a quite a while.

If you share a minimal example repo, we will be better able to see the same thing you do.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.