Description
Describe the bug
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).
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
.
- Restart sandbox browser until prefetch has failed
- Observe an exception being thrown when a retry to /api request succeeds
Expected behavior
I expect it to work fine.
How often does this bug happen?
Always
Screenshots or Videos

Platform
- OS: MacOS
- Chrome
- Dependencies:
"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