Next.js Discord

Discord Forum

revalidate a route segment with server actions

Answered
Satin Angora posted this in #help-forum
Open in Discord
Satin AngoraOP
I have a very simple app with two views. One displays a list of items and other details of an item. Now when a user is on item details page, they can change it. I have a server action on that page that updates the item. But the problem is, when the user goes back after the item is updated, it still shows the old item value. I revalidate the path with revalidatePath('/items') but it doesn't seem to work. I'm not sure what's going on. Can anyone help me with this?
Answered by Satin Angora
I can confirm, next/link fixes this cause it respects the revalidatePath set by the server action. It would use the cached version by default but If I do revalidatepath in a server action, it would fetch the path again. I think this should be documented somewhere. Anyways I'm posting here for posterity
View full answer

2 Replies

Satin AngoraOP
I think I forgot that router.back() has soft navigation and so the revalidatePath has no effect on it. Can anyone confirm?
Satin AngoraOP
I can confirm, next/link fixes this cause it respects the revalidatePath set by the server action. It would use the cached version by default but If I do revalidatepath in a server action, it would fetch the path again. I think this should be documented somewhere. Anyways I'm posting here for posterity
Answer