Webhook - delay between the webhook and ref update mechanism

Hello I have read this article about Prismic Webhook and ISR

I implement in my project and I encounter some problem

my webhook will trigger when a document is published and when my endpoint receive the webhook, I will revalidate the specific page which will query the prismic data

the problem is, I will get the old content occasionally

-> update the document from A to B and published
-> prismic trigger webhook
-> revalidate the page and log the content I query
-> I got the content A (should be B)
-> update the document from B to C and published
-> prismic trigger webhook
-> revalidate the page and log the content I query
-> I got the content B (should be C)

and sometime I can get the correct latest content..

I also log the result I query and I found if I got the old content

the ref parameter will be same and last_publication_date is wrong

is it possible that prismic trigger webhook but the ref is not update yet ?

can tell more about the mechanism of ref populated ?

Hello @client.mail.fe, thanks for reaching out.
How are you validating the page content after your site is rebuilt?

Hi @Pau , thanks for your response

since the page will use the data from prismic, I just check the page content like some string

I also log the query result in getStaticProps and I confirm that I got the old content

I also log the result in api endpoint

// If you have a `createClient()` function defined elsewhere in
    // your app, use that instead
    const client = prismic.createClient('your-repo-name')

    // Get a list of URLs for any new, updated, or deleted documents
    const documents = await client.getAllByIDs(req.body.documents)
   console.log('documents', documents). // >>> got the old content instead of latest content

so I am guessing there is a delay between the webhook and ref update mechanism (?)

Hello @client.mail.fe, are you using a catching system in your project?
The master ref is updated as soon as you make a new publication. If you get and query your documents with the most up-to-date ref you should be able to get the latest version of the content. You can double-check this in your repository's API browser. https://your-repo-name.prismic.io/api/v2

Hi @Pau

I am not using a cache system in my project

I check the ref value by fetching API after webhook hit my endpoint

here is pseudo code

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  const { type, documents, secret } = req.body;

  if (type === 'api-update' && documents.length > 0 && secret === 'XXX') {
    const result = await fetch('https://my-repo-name.cdn.prismic.io/api/v2').then(rawRes => rawRes.json());
    console.log('ref', result.refs[0]);
    await res.revalidate('/specific path'); // the page will fetch prismic document and log result using @prismicio/client

you can check result by video

Thanks for the example. Can you please send us the URL in your console and the URL of the document you're editing in the video?

Also, could you check if the ref in the console doesn't match the most recent one in your API browser?

Hi @Pau

How do I send the url to you ? is there any private message box I can use?

yes, the ref value does not match the API browser

I also create a github repo to reproduce this issue and I have own conclusion in the README, please check ! thanks

Hello, I sent you a dm where you can send the details.

I have sent you a dm, thanks !