await queryclient.prefetch()
in server component blocking entire root.
#7841
Replies: 1 comment
-
I guess this is the same behaviour as if you did Since of lately, you can not await the fetch, but pass the promise to the hydration boundary. See: https://tanstack.com/query/v5/docs/framework/react/guides/advanced-ssr#streaming-with-server-components The fetch will still happen on the server, and will be put into the cache, but at least it won't block anymore. If you want to avoid the refetch, you have to add caching on the server. That's an entirely different beast and out of scope for react-query. I have used cachified by Kent C. Dodds in the past for this and it works well: https://www.npmjs.com/package/@epic-web/cachified |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I currently have a problem in Nextjs where I'm prefetching some data on the server and then hydrating it to the client using
<HydrationBoundary state={dehydrate(queryClient)} />
.The fetch is working fine and the data is instantly accessible on the client when I'm using the traditional
useQuery
somewhere down the react tree.The issue that I'm running to is when i update the searchparams, for instance if i want to store a global state that the whole page can accesss (/home?calendarView={monthly || weekly }), the entire page slows down and I can only see the change after around 0.5 seconds. After some investigation i noticed that the
queryFn
gets called and awaited on the server and therefore, the change from changing for example the calendar view is very slow and weird (this happens also in production). Also in this case usinguseState
wouldn't make sense, since that would require tons of properties being passed through the react tree.Is there a way to prevent react query from refetching data on the server and avoid blocking the entire root?
Any help would be highly appreciated!
Here is my server component:
Here's my getQueryClient:
Beta Was this translation helpful? Give feedback.
All reactions