On-Demand Revalidation
Unanswered
Lionhead posted this in #help-forum
LionheadOP
I've been messing around with tag and path based on-demand revalidation in Next JS 13. I'm a little confused thought..the docs specifically state that revalidating with these methods will make the cache stale and will only refetch the data on the next request. However, when I use the revalidate('tagName') or revalidate('/path') it seems to be refetching AND reloading.
Can anyone shed some light on this? Why exactly does revalidate seem to be updating data on my screen, without me having to manually reload / refresh the page?
Can anyone shed some light on this? Why exactly does revalidate seem to be updating data on my screen, without me having to manually reload / refresh the page?
8 Replies
Normally, it’s true that users won’t get instantly updated after the revalidation unless they refreshing the page.
However, it depends on how and where do you call the revalidate function, for example, calling it in a server action will also mutate the data on client, which makes it updated.
However, it depends on how and where do you call the revalidate function, for example, calling it in a server action will also mutate the data on client, which makes it updated.
And in a route handler, it doesn’t
LionheadOP
Interesting. My particular use case is revalidating a server action from a client component, and it seems to still keep the ui data updated.
Is there some sort of router.refresh built in or something? Why exactly does this work?
Is there some sort of router.refresh built in or something? Why exactly does this work?
Well, this is actually a feature of server actions called “server-side data mutationsâ€, Next.js will mutate the data when a server action with on-demand revalidation is fired from the client.
LionheadOP
Oh very interesting!!
Does this apply to other server-side data mutations, like through route handlers or direct fetching in a server component, or is this specific only to server actions?
Does this apply to other server-side data mutations, like through route handlers or direct fetching in a server component, or is this specific only to server actions?
LionheadOP
To clarify, if I were to revalidate a server action from a server component, would it result in data updates if the data is displayed in a server component?
What about if I revalidate a route handler from either server or client components?
What about if I revalidate a route handler from either server or client components?
@Lionhead To clarify, if I were to revalidate a server action from a server component, would it result in data updates if the data is displayed in a server component?
What about if I revalidate a route handler from either server or client components?
Basically it is similar to
router.refresh, it will work regardless either it is a server component or not.