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
I believe there is some weird behaviour when a prefetchInfiniteQuery fails in a server component and useSuspenseInfiniteQuery retries to fetch the data on the client. The exception thrown is: Uncaught TypeError: Cannot read properties of undefined (reading 'length'). I have spent some time debugging into this, it feels like after the failure on the server, the client retries to fetch the data and upon a successful response, it doesn't modify the response to be in the expected {pages: [], pageParams:[]} format, but treats it like a normal query response.
I have also noticed that query options passed are ignored (such as retry: 0).
you’re right. when you’re not awaiting data on the server, we’re streaming the promise down. However, on the client, we try to pick up the promise by calling query.fetch here:
because that is what attaches the mechanism to transform data into { pages, pageParams }.
the conceptual problem I’m having now is that hydration doesn’t know about infinite / non-infinite query. There’s no information stored in the cache that knows about this.
here’s a more streamlined reproduction where the fetch always fails on the server and always succeeds on the client:
Interesting! Just like with the max update depth bug I think this is another argument for not passing the promise itself down, we need to wrap it with more metadata.
Describe the bug
I believe there is some weird behaviour when a
prefetchInfiniteQuery
fails in a server component anduseSuspenseInfiniteQuery
retries to fetch the data on the client. The exception thrown is:Uncaught TypeError: Cannot read properties of undefined (reading 'length')
. I have spent some time debugging into this, it feels like after the failure on the server, the client retries to fetch the data and upon a successful response, it doesn't modify the response to be in the expected{pages: [], pageParams:[]}
format, but treats it like a normal query response.I have also noticed that query options passed are ignored (such as retry: 0).
Your minimal, reproducible example
https://codesandbox.io/p/devbox/9lyl7g
Steps to reproduce
The sandbox has an API endpoint that is setup to fail randomly. Verify that the hardcoded endpoint path is correct in
pokemon.ts
.Expected behavior
I expect it to work fine.
How often does this bug happen?
Always
Screenshots or Videos
Platform
"next": "14.2.15",
"react": "18.3.1",
"react-dom": "18.3.1"
Tanstack Query adapter
None
TanStack Query version
5.62.7
TypeScript version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: