-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
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 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
- 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