Next.js Discord

Discord Forum

Incorrect behavior? Using dynamicParams = false with revalidatePath throws not-found page.

Unanswered
Oriental posted this in #help-forum
Open in Discord
OrientalOP
I was struggling with an issue, where I was revalidating a specific product following this route structure /product/[slug].

First, I generate all product pages with generateStaticParams by pulling all the product slugs from my CMS.
Second, when a product page updates, I revalidate that specific product page with
revalidatePath(`/product/${body.slug}`);


Once the page revalidates, it throws the not-found page. This does not happen in dev but does in build mode.

This doesn't seem like proper behavior (or at least what I would expect). My thoughts are, I want pages not generated with static params to throw the not-found page (therefore I use dynamicParams = false). It seems like after revalidating the page, it doesn't contain the same reference and next is considering it as something that was not generated statically.

I know that dynamicParams is the issue because if I change it back to dynamicParams = true, the revalidated product page shows up with the updated data while in build mode and does not throw the not-found page.

Is my approach incorrect? The only other idea I have is to use middleware to check if the slug exists in my CMS and throw notFound().

For example, I was just testing it by changing the heading text here.

0 Replies