Next.js Discord

Discord Forum

On-demand revalidation with SSG

Unanswered
Braque du Bourbonnais posted this in #help-forum
Open in Discord
Braque du BourbonnaisOP
I have a site that's entirely static and statically generated pages (home, about, work, work/[slug]). The content comes from a CMS called with fetch, every fetch request is tagged with next { tags: ['cms'] }. Every change in my CMS calls a route handler that calls revalidateTags(['cms']) and revalidatePath('/', type: 'layout'), with the goal being to completely replace the data cache and router cache when anything in the CMS changes.

On 14.0.0, this still isn't working consistently. Some changes work (changing a single piece of text in my CMS), but things like deleting a project (so that /work/old-project should 404) doesn't work. The old content sticks around and I can't seem to get it removed from the cache.

Is there a secret to SSG + On-demand revalidation?

9 Replies

Braque du BourbonnaisOP
I'm wondering if my issue is related to this part of the docs

During revalidation (ISR), generateStaticParams will not be called again.
generateStaticParams replaces the getStaticPaths function in the Pages Router.


So if my generateStaticParams is not called during ISR, the old pages wouldn't be deleted or added
Shy Albatross
Being pedantic maybe, but this is ISR, not SSG.
and yes, it does seem like that issue you quoted - or maybe not an issue, but a behavior
maybe, instead of trying to invalidate entire cache on every CMS update, you should do it on a per-item basis?
there's a lot of open issues on Next github directly calling out revalidation
Braque du BourbonnaisOP
@Shy Albatross almost like the ISR doesn't work, so it falls back to SSG, which has old stale values. I definitely want to switch to per-item, but I wanted to verify that the overkill (purging the entire cache) works first. If I can't get purging the entire cache to always show fresh data, it seems like the issue is internal.

If it is a Next issue, unfortunately this is for a client site so I have to find a temporary solve. Do you think completely turning off caching is my best bet, or possibly removing the generateStaticParams to force the /work/[slug] pages to be dynamic could help...
Braque du BourbonnaisOP
Alternatively, maybe the issue is because of this..."revalidating the data cache in a route handler will not immediately invalidate the router cache". Not sure what my option is if the revalidation needs to be called from the CMS, then it can't call a server action
Braque du BourbonnaisOP
Is there any way to opt out of the data cache but stick to only static rendering? Adding no-store to my fetch requests ensures I always have the latest data but this is a terrible solve for a static site, I'd rather just have to redeploy anytime something in the CMS changes
Shy Albatross
another thought, have you verified that the incoming request from CMS doesn't get cached? You know, if it's a GET it could get cached and wont' actually reach the route handler logic that triggers revalidation