Skip to content
Source
Sign inSign up
TanStack/query

throwOnError: false doesn't work with useSuspenseQueries #9711

Closedsheldhur(GitHub profile, opens in a new tab) opened this issue 3 comments

Describe the bug

useSuspenseQueries always throws an error even when throwOnError: false is set for all queries.

I see that the items passed to combine are typed as { data, error }, so I expected combine to be called regardless of errors.

However, combine is never executed when any query fails — even with throwOnError: false.

Your minimal, reproducible example

https://codesandbox.io/p/devbox/affectionate-pascal-n558wh?file=%2Fsrc%2Findex.tsx&workspaceId=ws_41uWiX86AQeXp6JvREFRri

Steps to reproduce

  1. use useSuspenseQueries
  2. set throwOnError: false for all queries
  3. throw error in some or all queryFn

uncomment line 41 in codesandbox

Expected behavior

I would like useSuspenseQueries to execute without errors, and I would like to have access to the errors in the combine function.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

Tanstack Query adapter

None

TanStack Query version

5.90.2

TypeScript version

5.6.3

Additional context

No response

  1. I think this issue is a fundamental design problem. The throwOnError option in useSuspenseQueries shouldn’t exist at all, as it contradicts the Suspense pattern.

    The official Docs also specifies that the throwOnError option does not exist.

  2. I looked at the source code of useSuspenseQueries and tried to use useQueries with { suspense: true, throwOnError: false } but nothing changed. I'm trying changing throwOnError to callback but it is never executed too

    In my case all but one of the queries aren't necessary. Is there any way to do this without wrapping all the queryFn in a try/catch?

    I don't want use useQueries without suspense for not necessary queries because I'll have to add another loading handler in each component

  3. TkDodocommented

    throwOnError is not allowed for suspense because we set this internally. Your reproduction even has a type error because of it:

     Object literal may only specify known properties, and 'throwOnError' does not exist in type 'UseSuspenseQueryOptions<string, unknown, unknown, readonly unknown[]>'.
  4. TkDodo closed this

  5. TkDodo added labelsworks as designed

Sign in to join this conversation.