Nextjs Route Cache using Tags (ISR)

Hey, I was just wondering if it is possible to use tags for full routes in next. Usually when I implement some ISR logic, I do something like this
// app/products/page.tsx
export const dynamic = "force-static";

export default async function ProductsPage //...
// app/products/page.tsx
export const dynamic = "force-static";

export default async function ProductsPage //...
Then I can do revalidatePath('/products') to invalidate the cache. Now I ended up building a nice caching system for my data cache using using "next/cache" and tags. I have some webhooks in place that invalidate tags and therefore refresh my data. My question is: can I also tag pages with some string value(s)? So that I can revalidate them with the same revalidateTag call? I personally prefer this way as it allows you to specify what data a route depends on in the route itself. Otherwise when I update some data, I have to think of all routes that use it and revalidate the paths one by one. Later one seems much more error prone to me.
Solution:
Update: Interestingly, I don't need that anymore. It seems Nextjs is smart enough to remember what data calls are being used for pre-rendering the page. When I build and deploy, it pre-renders and cache the full route. When I then revalidate a tag for my data cache, it will also re-render the page on the next request and cache that newer version. Pretty nice - seems like I missed that from the docs.
Jump to solution
1 Reply
Solution
Niklas
Niklas2w ago
Update: Interestingly, I don't need that anymore. It seems Nextjs is smart enough to remember what data calls are being used for pre-rendering the page. When I build and deploy, it pre-renders and cache the full route. When I then revalidate a tag for my data cache, it will also re-render the page on the next request and cache that newer version. Pretty nice - seems like I missed that from the docs.
Want results from more Discord servers?
Add your server