Next.js Discord

Discord Forum

Question about revalidatePath 'type' params

Answered
Jumbo flying squid posted this in #help-forum
Open in Discord
Jumbo flying squidOP
For the type param, i see the below info in the docs:
"type: (optional) 'page' or 'layout' string to change the type of path to revalidate. If path contains a dynamic segment (for example, /product/[slug]/page), this parameter is required. If path refers to the literal route segment, e.g., /product/1 for a dynamic page (e.g., /product/[slug]/page), you should not provide type."

My question: it says you shouldn’t provide type if using literal route segment. Why? Which cache does it clear then in that case? Page or Layout cache, or Both? Just curious why it doesn't want you to supply the param and assumes some value instead (if so which one).
Answered by luis_llanes
I assume if you revalidate “/product/1” you’re revalidating only the page for product 1. I wanna believe Next.js opts for using the page revalidation as the default, that way you only purge 1 cache instead of n

If you do “/product/[slug]” basically slug is a placeholder for whatever value
View full answer

31 Replies

I assume if you revalidate “/product/1” you’re revalidating only the page for product 1. I wanna believe Next.js opts for using the page revalidation as the default, that way you only purge 1 cache instead of n

If you do “/product/[slug]” basically slug is a placeholder for whatever value
Answer
Ok so @Jumbo flying squid
Imagine you have 3 pages
/user/bob
/user/jacob/cart
/user/bob/cart
Now imagine you want to revalidate only the cache for bob's page
You would just do revalidateTag("/user/bob")
No type param means you just did the page string
Which means it will only revalidate that page
Jumbo flying squidOP
so it does not do layout as well, otherwise it would also revalidate jacobs layout which we( and NextJS) shouldn't assume. so only 'page' is assumed
Yes
If you use the layout param, it will revalidate both /bob and /bob/cart
Essentially go down the layout tree and revalidate all pages under it
For example, if you want to revalidate all the caches in your app
What would you use?
Based on what I explained above
Jumbo flying squidOP
revalidatePath('/', 'layout') would it be that? since 'page' only does that particualr page and doesnt go down the layout tree
Yes
Jumbo flying squidOP
and layout would go down the tree
Absolutely
Jumbo flying squidOP
cool. i got it
Bingo
Nice, mark an answer
Jumbo flying squidOP
Question, how do i mark an answer here :). I am using the web version and dont see any 'Mark as Answer' functionality next to your posts
i see a 'Close Post' option on the parent level at the top. although not sure thats it
Right click on the message (or hold down on Phone) > Apps > mark solution
^^
Original message was deleted
Like this
Jumbo flying squidOP
got it 🙂
Thanks @Arinji !
Awesome, no worries
Jumbo flying squidOP
ill post more questions next few days as i read the docs 🙂