Skip to content

useSuspenseQuery has incorrect behavior on select errors #8039

Closed

Description

Describe the bug

useSuspenseQuery seems to have incorrect behavior when select function throws an error. Right now if the select function throws an error, data is set to undefined, which goes against the typed return type.

When queryFn throws an error, it is correctly propagated.

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/qf5gdz

Steps to reproduce

Use the following query and see that query.data is undefined.

const query = useSuspenseQuery({
  queryKey: ["key"],
  queryFn: () => "my-result",
  select: () => {
    throw new Error("Something went wrong during select");
  },
});

Expected behavior

useSuspenseQuery should propagate errors being thrown from select, just like when they are thrown from queryFn.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Irrelevant

Tanstack Query adapter

react-query

TanStack Query version

v5.55.4

TypeScript version

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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