Next.js Discord

Discord Forum

Update Page Data when Navigating?

Answered
Orinoco Crocodile posted this in #help-forum
Open in Discord
Orinoco CrocodileOP
I have a cart page that uses server code to fetch the carts data and render it. When I open the cart, then navigate to a product to put an item in the cart and go to the cart page again, it shows the old cart. Thought it was supposed to update, but clearly the client is caching the old cart page from previous navigation.

I'm wondering how to opt out as I used fetch no-cache options in my cart API calls and I put these on top of my page:

export const dynamic = 'force-dynamic';
export const revalidate = 0;
Answered by joulev
put an item in the cart
do this in a server action with a revalidateTag/revalidatePath call
View full answer

6 Replies

if you can refresh page and its correct, then its probably client router cache: https://nextjs.org/docs/app/building-your-application/caching#router-cache
put an item in the cart
do this in a server action with a revalidateTag/revalidatePath call
Answer
if you use server actions with revalidate* or router.refresh() on client, it can clear it (id recomend server action)
oh lol i was too slow and joulev said what i said in better words and speed
Orinoco CrocodileOP
I see, thank's a lot!!
What is a cache tag though?