On-Demand ISR on publication with Next.JS 12.1


Recently, I set up On-Demand Incremental Static Regeneration with a DatoCMS project and a Next.JS 12.1 site.

This was quite straightforward to implement with a DatoCMS webhook and a Next.JS function. In general, this setup works great. This is much more intuitive for editors, as they don’t have to understand/remember the extra deploy step (which apparently is a hard-to-grasp SSG-specific concept for non-tech people) to get content live. An awesome improvement for content management with static sites.

For those interested, I uploaded the code of my setup to a Gist: instantly publish DatoCMS pages with Next 12.1 On-Demand ISR · GitHub

I have one thing I’d like to see improved: the webhook payload should contain the model API key directly instead of only the model ID (payload?.entity?.relationships?.item_type?.data?.id), which seems to be subject to change, e.g. when forking environments or changing the model, while the model API key remains stable.

However, the model identity is required to determine the set of page paths to revalidate/update.

So I hardcoded a mapping for that, which is not ideal. An improvement I could do, is storing model IDs as env vars, then I wouldn’t have to change code if they change, but also not ideal, as I still needed to change the env vars in Vercel and do a redeploy. If the webhook data contained the model API key that issue would be gone.



Thank you for sharing @kf !

While here, I also would like to share this video on the same topic:

That can be useful to get a more all-rounded explaination :slight_smile:

Also about your request, I’m linking it from here: Include alphanumeric model IDs in Webhook payloads and Content Delivery API payloads as it might be useful.

Thank you!

1 Like