#how revalidate path works.

34 messages · Page 1 of 1 (latest)

mossy marsh
#

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?

vocal auroraBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

sleek crystal
#

yes, redirects also trigger the new cache

mossy marsh
sleek crystal
mossy marsh
mossy marsh
#

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

mossy marsh
#

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

sleek crystal
mossy marsh
#

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?

sleek crystal
#

it would surely update? what makes you think it won't?

mossy marsh
#

Making a new request to the server, re-fetching data requests, and re-rendering Server Components
it doesnt say anything about client components

sleek crystal
mossy marsh
#

mb

#

give me a couple minutes

#

i will come back and show some code

mossy marsh
#

im calling router.refresh() on a client side when a form is submitted succesfully.
this is my aside

#

i just realized that ts console.log('mounted') never runs when i run ```ts
router.refresh()

mossy marsh
#

I have moved it into a server component and now it re-renders when i call router.refres()

#

its working!