Next.js Discord

Discord Forum

In need of a better understanding of revalidating.

Unanswered
Stabyhoun posted this in #help-forum
Open in Discord
StabyhounOP
I currently have a route which looks something like /users/[userId], where logged in users can edit their profile. In this path, I use server actions to update the user's profile, and here I take advantage of the revalidateTag to refresh the fetch requests, and therefore updating the UI with the new user data. However, this type of revalidation only works if the user is currently on this route, which they will always be in this case. However, the situation below differs.

There are two different routes to the users' posts. One route: /users/[userId]/post which is the route a user uses to post something. Then the second route: /users/[userId]/posts, which is the route to display a user's posts. After creating a user post in the /users/[userId]/post route, and you navigate back to /users/[userId]/posts, the newly created post is nowhere to be found until the page is refreshed. Attempting to use the same logic as the update profile explanation above is pointless, as different routes completely renders router.refresh, revalidatePath and revalidateTag useless.

So the question is: what could I do to invalidate certain routes' cache and refetch their data upon navigating to the routes?

0 Replies