Revalidate unpublished documents on ISR


Stumbled into following problem, while doing some revalidation logic into my project. Let's say we unpublish (aka delete something from production) and then we would trigger webhook, which would do request into our API endpoint inside Next.js project.

So far everything works as expected, as we get deleted document inside with "body.documents" array. Now next step (after all conditions checking, checking array has data etc.) would be revalidate our deleted path, so we would do something following:

await revalidate("my_path comes_here")

Thing is I can't put the deleted document ID there, because that path does not exist on our project. As for example when I build the project and "getStaticPaths" would be executed, we would (just for reference!) get following paths:

  • "/"
  • "/about"
  • "/projects"

So we don't have path called "/ZXrpJBEAABJLMmsX" for example. And this would mean that Next.js would actually try fetch document based on this ID, but obviously there would be no data at Prismic, so we would get 404 error for this path.

I was thinking to fetch meta data based on this document ID (using GraphQL) eg:

const { data } = await getAllPagesMeta({
    currentDocumentsID: getDeletedDocumentsID,
    filterDocuments: ['landing_page', 'project'],
    latestReference: getLatestMasterRer,

But then realised that, the "masterRef" value which we get with payload would give us the latest data, which means on latest data this deleted document does not exist anymore. My idea was originally get deleted document "uid" value (which we use for generating every pages paths).

Hey @aarnipavlidi,

This is true! We plan to update our blog post on ISR to address this problem.

Our recommended workaround is to fire a webhook when you publish or change a document and update the page via ISR; but, if you delete a document, fire a different webhook to trigger a full site rebuild.

I hope that helps!


Hey, thanks for you answer!

I could look into that from Prismic we are going to trigger into Vercel API endpoint for rebuilding project e.g:<id_value_here

But then question remains is it problematic that what if we unpublish/delete multiple documents. As I am using Hobby plan (doing portfolio project), it's very unlikely I am going to reach those limits when it comes to how much project is spending building per each month, but neverthless it's still one thing for me to be aware of.

It would be awesome (for the future) that the payload what we get from webhook would consist both "id" and "uid" values. So something like following:

documentsNew: [{ id: string, uid: string }...];
documents: [array of strings]; of the body

We probably can't change structure of the "documents" straight away, as people have made their logic into their current projects, where they assume that "documents" is array of strings, so hence we could either create new array with both "id" and "uid" or create array with only "uid" so e.g:

documents: [array of strings];
uids: [array of strings]; of the body

But then can we assume that both are on same order (maybe I am overthinking :D)?

Anyways thanks for your answer and have good weekend!

Hey @aarnipavlidi, you can unpublish multiple documents as part of a release to only trigger a rebuild once.

That's a nice idea, although it's not something in our plans at the minute.

I'm not sure about this, you'd need to test, would they even need to be in the same order?