Calling revalidatePath on statically generated page is throwing not-found file during build
Unanswered
Oriental posted this in #help-forum
OrientalOP
I am trying to revalidate a product page in response to a webhook. The webhook works fine, it's the revalidation that doesn't seem to be working. For example I have some SSG paths under /product/[slug] .
When a specific product updates in the CMS, I am calling revalidatePath('/product/some-product'). Once this happens, I refresh the page to check if it updated, but instead of showing the product page it now shows my not-found.tsx file.
In dev mode, the product page is just not updating with the new data. it just keeps returning the now stale data.
For example, here the name is LIBLAR, I update it to LIBLARYE, and I still continue to get LIBLAR.
When a specific product updates in the CMS, I am calling revalidatePath('/product/some-product'). Once this happens, I refresh the page to check if it updated, but instead of showing the product page it now shows my not-found.tsx file.
In dev mode, the product page is just not updating with the new data. it just keeps returning the now stale data.
For example, here the name is LIBLAR, I update it to LIBLARYE, and I still continue to get LIBLAR.
//here's how I am revalidating the path
//I am getting the slug in my webhook based on the product that updated in my CMS
revalidatePath(`/product/${body.slug}`);
4 Replies
OrientalOP
These two images are from build mode. Notice the api gets hit, it revalidates. then I refresh the page, and now I get my not found page
Are you creating pages depending on the product name?
Is
Because if you changed the name and this resulted in the change of the slug too, makes sense that next.js can’t find it anymore.
Try using a unique ID as
Is
[slug]
a unique Id that persists even after you change the name or is [slug]
the name of your product? Because if you changed the name and this resulted in the change of the slug too, makes sense that next.js can’t find it anymore.
Try using a unique ID as
[slug]
so when you revalidate you re-fetch the data for that corresponding ID.@LuisLl Are you creating pages depending on the product name?
Is `[slug]` a unique Id that persists even after you change the name or is `[slug]` the name of your product?
Because if you changed the name and this resulted in the change of the slug too, makes sense that next.js can’t find it anymore.
Try using a unique ID as `[slug]` so when you revalidate you re-fetch the data for that corresponding ID.
OrientalOP
Yes slug is a unique id that each product in the system has. all I am changing in the system is the name of the product (not the slug! the slug does not change)
I did fix the issue where the changes weren't reflecting on dev mode. I had to disable a CDN setting in my CMS system, but the issue with the not-found page showing up after revalidating still occurs when in build mode.