Why Does revalidatePath('/users') Automatically Update User Data on the Same Page in Next.js?
Unanswered
American posted this in #help-forum
AmericanOP
In my Next.js app, I have a server component that fetches user data using an API call and renders a client component. Inside the client component, I perform a mutation via a server action to update the user data (e.g., adding or modifying a user), and after the mutation, I call revalidatePath('/users'). Why does the page display the updated user data immediately without requiring me to navigate away or manually refresh, even though I remain on the same /users page?
in the docs its saying that revalidatePath only invalidates the cache when the included path is next visited.
have i got it wrong ?
in the docs its saying that revalidatePath only invalidates the cache when the included path is next visited.
have i got it wrong ?
2 Replies
@American In my Next.js app, I have a server component that fetches user data using an API call and renders a client component. Inside the client component, I perform a mutation via a server action to update the user data (e.g., adding or modifying a user), and after the mutation, I call revalidatePath('/users'). Why does the page display the updated user data immediately without requiring me to navigate away or manually refresh, even though I remain on the same /users page?
in the docs its saying that revalidatePath only invalidates the cache when the included path is next visited.
have i got it wrong ?
when a server action has a
revalidate*
call that matches with some data on the page, it will also rerun the page component and send the fresh new data in the response, that's why it updates the user data^^ What he said, Server Actions return the fresh data + the new RSC payload of the updated UI in a single roundtrip
What you mentioned the docs say about
What you mentioned the docs say about
revalidatePath
, applies for the cases where you trigger a revalidation outside of a Server Action and for the paths/tags you’re not currently on.