revalidating data on server clears tanstack queryClient #9124
-
In nextjs 15 when revalidating server side cache using actions clears the client side queryClient. I am not sure what I am missing here but I am not able to find any helpful material online which could help me resolve this issue. I am attaching repo to reproduce this bug steps:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Issue was with creating queryClient directly. initializing QueryClient using state solved the issue.
When initializing QueryClient directly in layout or provide causes issues when revalidation actions are called. The reason being is that when the server side cache is cleared it cause layout re-render and hence QueryClient is re-initialized. Wrapping QueryClient in useState solves this problem. special thanks to : |
Beta Was this translation helpful? Give feedback.
Issue was with creating queryClient directly.
initializing QueryClient using state solved the issue.
When initializing QueryClient directly in layout or provide causes issues when revalidation actions are called. The reason being is that when the server side cache is cleared it cause layout re-render and hence QueryClient is re-initialized. Wrapping QueryClient in useState solves this problem.
special thanks to :
ISDuffy's comment
and
https://www.youtube.com/watch?v=b_UQ1bdQddw&t=419s
for providing solution