You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
have a HydrationBoundary in a Next.js app which dehydrates a query that contains prefetched queries which have not been awaited serverside (ie. they are promises which are being serialized to work with suspense)
the initial page load works correctly with the serverside prefetch data becoming available on the client
submit a server action which does something that causes the prefetching component to refetch and re-render (For example, revalidatePath)
even though the prefetch request is sent again when this happens, react query on the clientside does not seem to update its query cache with the new data when the new prefetch promise resolves
this flow works properly when the prefetch is awaited serverside, ie. instead of sending a promise in the HydrationBoundary we send the resolved data. In that scenario the clientside cache is updated correctly when the same "server action + revalidatePath" function is called.
download the stackblitz (it doesn't work when running in their environment due to some mysterious "missing queryFn" error that doesn't happen locally)
npm install && npm run dev
visit localhost:3000 and click the "new pokemon" button. Notice that there is no new pokemon
visit localhost:3000/awaited and click the "new pokemon" button. Notice that there is a new pokemon.
Expected behavior
I would expect that the new promise triggered by the server action and sent down in the response should update the clientside query cache when it resolves. Instead this only seems to happen if the promise is awaited serverside and the data is sent in the HydrationBoundary rather than the promise.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OS: mac
browser: chrome
Tanstack Query adapter
react-query
TanStack Query version
5.61.5
TypeScript version
5.3.3
Additional context
the stackblitz I set up is based on the example linked in the Advanced Serverside Rendering guide, which does not seem to build successfully and may need to be updated: https://tanstack.com/query/latest/docs/framework/react/examples/nextjs-app-prefetching
I attempted to fix it by overriding the dependencies etc. but then I still received an error about a missing queryFn from react-query even though the queryFn was definitely set. This error does not happen when running the same code locally.
The text was updated successfully, but these errors were encountered:
From a quick skim, it seems like it! I'll take a deeper look later, but thanks so much for the reproduction @ajwootto, I've seen this before but it's been elusive.
Describe the bug
Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-query-fit2ih?file=app%2Fpage.tsx
Steps to reproduce
npm install
&&npm run dev
localhost:3000
and click the "new pokemon" button. Notice that there is no new pokemonlocalhost:3000/awaited
and click the "new pokemon" button. Notice that there is a new pokemon.Expected behavior
I would expect that the new promise triggered by the server action and sent down in the response should update the clientside query cache when it resolves. Instead this only seems to happen if the promise is awaited serverside and the data is sent in the HydrationBoundary rather than the promise.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
react-query
TanStack Query version
5.61.5
TypeScript version
5.3.3
Additional context
https://tanstack.com/query/latest/docs/framework/react/examples/nextjs-app-prefetching
I attempted to fix it by overriding the dependencies etc. but then I still received an error about a missing queryFn from react-query even though the queryFn was definitely set. This error does not happen when running the same code locally.
The text was updated successfully, but these errors were encountered: