how revalidate path works.
Answered
Common Moorhen posted this in #help-forum
Common MoorhenOP
the next js docs say that
does that mean that i need to navigate to that page redirecting from the backend? or can i just wait for the server action to finish and then call
will it work if i call
revalidatePath only invalidates the cache when the included path is next visited. This means calling revalidatePath with a dynamic route segment will not immediately trigger many revalidations at once. The invalidation only happens when the path is next visited.does that mean that i need to navigate to that page redirecting from the backend? or can i just wait for the server action to finish and then call
router.push('/my-uncached-route') on the client side?will it work if i call
router.refres() on the client too?Answered by Common Moorhen
I have moved it into a server component and now it re-renders when i call
router.refres()32 Replies
@Common Moorhen the next js docs say that
revalidatePath only invalidates the cache when the included path is next visited. This means calling revalidatePath with a dynamic route segment will not immediately trigger many revalidations at once. The invalidation only happens when the path is next visited.
does that mean that i need to navigate to that page redirecting from the backend? or can i just wait for the server action to finish and then call `router.push('/my-uncached-route')` on the client side?
will it work if i call `router.refres()` on the client too?
if you do revalidatePath, then that cache will be invalidated. A new cache will be there as soon as you visit the page, by any means
yes, redirects also trigger the new cache
@Anay-208 if you do revalidatePath, then that cache will be invalidated. A new cache will be there as soon as you visit the page, by any means
Common MoorhenOP
aah okay, so the docs are not saying that if i use
revalidatePath() and then i dont navigate to that page, it wont delete the cache. what it is saying is that i won't see the cache until i visit that page?@Common Moorhen aah okay, so the docs are not saying that if i use `revalidatePath()` and then i dont navigate to that page, it wont delete the cache. what it is saying is that i won't see the cache until i visit that page?
Right, the cache will just be invalidated. Not sure about deletion.
You'll just see a new cache when you next visit the page
You'll just see a new cache when you next visit the page
@Anay-208 Right, the cache will just be invalidated. Not sure about deletion.
You'll just see a new cache when you next visit the page
Common MoorhenOP
can I just call a revalidate path in the same route the user is currently on, then after the server action runs I call
router.refresh() ? or does it need to be a full reload?Common MoorhenOP
yes i will
sure
i had problems doing that
so i didnt know if it was because i was doing it wrong or if its not possible
Common MoorhenOP
aah wait
it triggers a cache invalidation, not a a re-request
so if im a path with a layout and i submit a form that changes the layout data, even if i revalidate the cahce, it wont change the layout data
Common MoorhenOP
yep
i have realized that my component is a client component
and i just read this
router.refresh(): Refresh the current route. Making a new request to the server, re-fetching data requests, and re-rendering Server Components. The client will merge the updated React Server Component payload without losing unaffected client-side React (e.g. useState) or browser state (e.g. scroll position).it would not update?
it would surely update? what makes you think it won't?
Common MoorhenOP
Making a new request to the server, re-fetching data requests, and re-rendering Server Componentsit doesnt say anything about client components
@Common Moorhen i have realized that my component is a client component
how are you fetching data then?
mb
give me a couple minutes
i will come back and show some code
@Anay-208 how are you fetching data then?
Common MoorhenOP
hi, sorry for the delay
im calling router.refresh() on a client side when a form is submitted succesfully.
this is my aside
this is my aside
i just realized that
console.log('mounted') never runs when i run router.refresh()Common MoorhenOP
I have moved it into a server component and now it re-renders when i call
router.refres()Answer
Common MoorhenOP
its working!