server error with nextjs , and hydration in v5 #8528
Send to my agentDescribe the bug#
server error with nextjs , and hydration in v5
Your minimal, reproducible example#
Steps to reproduce#
- it does not need any steps , it occur when you starting the app (event on dev or production mode).
Expected behavior#
as a user , i don't except this error happen , and it make some conflicts with building and compiling for production
How often does this bug happen?#
Every time
Screenshots or Videos#
Platform#
- OS : [MacOS - stackblitz]
Tanstack Query adapter#
react-query
TanStack Query version#
"^5.64.0" ,
TypeScript version#
"5.7.2"
Additional context#
No response
TkDodo added labelsbug
Regarding this issue, could this be the reason that the data are not fetched in the server side? As it can be seen in the provided link, the /pokemon api should be fetched on server side since it uses the prefetch, hydration and query client techniques. However, it can be observed in the chrome dev tools that the query is fetched in client side.
Regarding this issue, could this be the reason that the data are not fetched in the server side? As it can be seen in the provided link, the /pokemon api should be fetched on render side since it is used the prefetch, hydration and query client techniques. However, it can be observed in the chrime dev tools that the query is rendered in client side.
Actually i follow that issue and reached here , i amazed why that happens. That is good question too
However, it can be observed in the chrome dev tools that the query is fetched in client side.
It is fetched on the client side because we don’t pass an
initialPromisetoquery.fetch, so it tries to execute an actual fetch, without aqueryFn(so this can’t work).@juliusmarminge @Ephem this issue is baffling to me. maybe there is something that changed with next15 and using
.thenon this weirdReactPromisedoesn’t work anymore?hmm am i missing something? seems to work fine for me locally:
Huh,I was debugging it on stackbiltz (in a separate tab). Maybe it’s just a stackblitz issue then?
hmm yea - installed the same node version (18.20) locally and ran with that and still working fine
Hm, works locally for me too. It's an interesting one though. For some reason we are still trying to fetch during SSR and not finding the
queryFnwhen doing so, but when I add some basic logging for both thepromiseand thequeryFnboth seem to be there correctly. 🤔hmm am i missing something? seems to work fine for me locally:
i tried to implement this on nextjs 15.3 , and this happen yet . what react-query version you used ?
Closing this since it's working fine for anything but stackblitz.
TkDodo closed this
Sign in to join this conversation.
Thanks for filing. I’m not 100% sure what’s going on, but I debugged it a bit and the gist is that the
initialPromiseis passed asundefinedtoquery.fetchhere:https://github.com/TanStack/query/blob/bd3296bfed9b4db1882e42fe378f2f35dc240381/packages/query-core/src/hydration.ts#L215-L219
That leads to us invoking the
queryFn(because we have no promise to re-use), but thequeryFndoesn’t exist yet, so it errors:https://github.com/TanStack/query/blob/18953be6f61553f4ed3dd888945dfa1683aa6e40/packages/query-core/src/retryer.ts#L153
When inspecting the
promisewe get from the server, it’s there, butinitialPromiseis stillundefined:@juliusmarminge does this have something to do with
.then(deserializeData)? Before that step, the promise seems to still be there.deserializeDatais just our default one:https://github.com/TanStack/query/blob/bd3296bfed9b4db1882e42fe378f2f35dc240381/packages/query-core/src/hydration.ts#L17-L19