Describe the bug
The combine function in useSuspenseQueries has types that narrow data to always be defined (non-undefined), implying it should only be called when all queries have successfully resolved. However, combine is actually invoked via QueriesObserver.#combineResult in the #notify path even when query results are in pending or error state (e.g., after queryClient.resetQueries() or when a query errors out).
This causes a runtime TypeError because user code in combine reasonably accesses .data without null checks — as the types suggest it is safe to do so.
Your minimal, reproducible example
https://codesandbox.io/p/devbox/wonderful-pine-74lmth?workspaceId=ws_QZPvCEAK42bpnZ7RJHDjaX
Steps to reproduce
- Open the reproduction link above.
- Confirm that
loading... is displayed on the initial load.
- Open the console in the Preview panel.
- In DevTools, select a query and trigger loading or trigger error. Or click the
reset query button.
Uncaught TypeError: Cannot read properties of undefined (reading 'full_name') error is thrown.
Expected behavior
One of the following:
-
If combine is intended to only receive successful results, combine should not be called when any query result is in a non-success state. The observer notification path should skip the combine optimization and let the framework render path handle suspension or error boundaries.
-
If combine is intended to handle all states, The type signature of combine in useSuspenseQueries should reflect that data can be undefined, matching the runtime behavior.
How often does this bug happen?
Always
Screenshots or Videos
Platform
- OS: macOS
- Browser: Chrome
- Version: 144.0.7559.97
Tanstack Query adapter
react-query
TanStack Query version
v5.90.21
TypeScript version
v5.8.3
Additional context
React Version: v19.2.14
Describe the bug
The
combinefunction inuseSuspenseQuerieshas types that narrowdatato always be defined (non-undefined), implying it should only be called when all queries have successfully resolved. However,combineis actually invoked viaQueriesObserver.#combineResultin the#notifypath even when query results are inpendingorerrorstate (e.g., afterqueryClient.resetQueries()or when a query errors out).This causes a runtime
TypeErrorbecause user code incombinereasonably accesses.datawithout null checks — as the types suggest it is safe to do so.Your minimal, reproducible example
https://codesandbox.io/p/devbox/wonderful-pine-74lmth?workspaceId=ws_QZPvCEAK42bpnZ7RJHDjaX
Steps to reproduce
loading...is displayed on the initial load.reset querybutton.Uncaught TypeError: Cannot read properties of undefined (reading 'full_name')error is thrown.Expected behavior
One of the following:
If
combineis intended to only receive successful results,combineshould not be called when any query result is in a non-successstate. The observer notification path should skip the combine optimization and let the framework render path handle suspension or error boundaries.If
combineis intended to handle all states, The type signature ofcombineinuseSuspenseQueriesshould reflect thatdatacan beundefined, matching the runtime behavior.How often does this bug happen?
Always
Screenshots or Videos
Platform
Tanstack Query adapter
react-query
TanStack Query version
v5.90.21
TypeScript version
v5.8.3
Additional context
React Version: v19.2.14