Skip to content

useSuspenseQueries combine is called with pending/error results despite types implying data is always defined #10129

@dolphinlmg

Description

@dolphinlmg

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

  1. Open the reproduction link above.
  2. Confirm that loading... is displayed on the initial load.
  3. Open the console in the Preview panel.
  4. In DevTools, select a query and trigger loading or trigger error. Or click the reset query button.
  5. Uncaught TypeError: Cannot read properties of undefined (reading 'full_name') error is thrown.

Expected behavior

One of the following:

  1. 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.

  2. 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

Image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions