Skip to content
Source
Sign inSign up
TanStack/query

useQueries and useSuspenseQueries don't throw falsy errors to the error boundary #11304

Closedalex-js-ltd(GitHub profile, opens in a new tab) opened this issue 0 comments

Describe the bug

When a queryFn rejects with a falsy value (Promise.reject(), null, '', 0), useQuery throws it to the nearest error boundary, but useQueries and useSuspenseQueries do not.

useSuspenseQueries is the worst case: it renders with data === undefined, even though its types declare data as always defined — so user code dereferences undefined and fails with an unrelated TypeError.

useQueries guards its throw with if (firstSingleResultWhichShouldThrow?.error). The optional chain is needed to narrow Array.prototype.find's T | undefined, but the truthiness check on .error also skips the throw when the error value is falsy. useBaseQuery has no equivalent check.

Your minimal, reproducible example

https://stackblitz.com/edit/github-xu81gzmb?file=src%2Findex.tsx

Steps to reproduce

  1. Open the StackBlitz link.
  2. Each of the three hooks rejects with Promise.reject() (i.e. undefined) inside its own ErrorBoundary.
  3. Only the useQuery boundary renders. The useQueries and useSuspenseQueries boundaries do not.

Expected behavior

All three hooks should throw to their error boundary, as useQuery does.

Given identical options and an identical rejection:

hooktruthy errorfalsy error
useQuery + throwOnErrorboundary ✅boundary ✅
useQueries + throwOnErrorboundary ✅never throws ❌
useSuspenseQueriesboundary ✅renders data === undefined ❌

How often does this bug happen?

Every time

Platform

  • OS: macOS
  • Browser: any (reproduces in the StackBlitz sandbox)

Tanstack Query adapter

react-query

TanStack Query version

v5.102.5

TypeScript version

v5.8.3

Additional context

Happy to open a PR — I have a one-line fix and regression tests locally.

  1. TkDodo added labelspackage: query-core

  2. TkDodo closed this

Sign in to join this conversation.