revalidatePath seems not to be working from App Router #51156
Replies: 2 comments 4 replies
-
I think, within an API Route there's no communication between the APP and the Server Side runtime, to get immediate feedback, that's where Server Actions kick in: https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions So you gotta define a server action and call it when you want to invalidate the client side server component cache. When does I am bit foggy on |
Beta Was this translation helpful? Give feedback.
-
Although you put a revalidatePath inside server action, if that particular action is getting called inside client component, it won't work. method call should be also in the server component and should pass the data as prop to subsequent client components if have |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hola,
This is my /app/api/revalidate endpoint:
In my /app/layout.tsx root layout I'm calling a dummy fetch method:
My expectation was, that the fetch() will be executed each time I hit the revalidate endpoint with request body {'path':'/'}, but this only happens once or not at all in my VsCode terminal.
The underlying problem is that I'm looking for a way to re-render my root layout as it contains the global navigation bar with links that should be displayed/hidden based on the login state of the user. So, at least after login or logout, I want the root layout to check again, if a JWT token is present with the next request but I just don't get what'd be the best approach for that. Even if revalidatePath caused all fetches to be executed again, the JWT token would'nt be available because it is supposed to be retrieved from the cookies() function upon client request and passed to fetch('/api/auth/status') as x-access-header to check if the token is valid... I'm confused.
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions