Next.js Discord

Discord Forum

Configure ISR to render on startup

Unanswered
Derock posted this in #help-forum
Open in Discord
My site's homepage fetches statistics from an endpoint not accessible via build time, and instead falls back to using some default values. (using a fetch(..., { next: { revalidate: 3600 } })). How can I force Next.js to re-render this page on startup, so that the "stale" statistics the server serves are not the default values I've set.

Basically:
- build starts generating my homepage
- server component fetch fails, so code falls back to some default values
- next.js finishes rendering this page, and saves it
- build finishes, and is deployed to production
- since it is not past 1 hour, (the revalidate time I've set), next.js happily serves the page with the default values, despite that fetch failing.
- after one hour, the next request will still show the stale/default content while next.js revalidates in the background

What I want to do instead is force next.js to render the page at startup. I don't want to force this page to be always dynamic as it's mainly static except for a small portion, and I don't want to introduce a suspense since that would mean adding in a fallback loading state.

I've tried calling revalidateTag in instrumentation hook, but it does not work there (throws an invariant error).

next 14.2.0

1 Reply

how did you use revalidateTag