-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useSuspenseQuery
has incorrect behavior on select
errors
#8039
Comments
useSuspenseQuery
has incorrect typing for isError
and wrong behavior on select
errorsuseSuspenseQuery
has incorrect behavior on select
errors
Just as a side-note: I heavily rely on |
This is a "known limitation" of how select works. Every observer (useQuery instance) can have it's own select. We cannot put the Query in |
Explaining why you should not thow errors in the select function Closes TanStack#8039
Explaining why you should not thow errors in the select function Closes TanStack#8039
So in which place do you recommend to convert JSON values into non-JSON serializable objects in a fallible way? Doing that in the query function itself wouldn't work, as that would lead to components re-rendering every time as they'd think that the fetched values changed. |
I'd say use something like https://zod.dev/?id=datetimes in the (If you control your own backend you could probably skip it with trpc and branded types even) |
That does sound like doubling logic, especially for pretty deeply nested objects. I'm already using Zod for validation and transformation at the same time (via I suppose I could run the zod schema within the query function itself for validation, and then again in the selector to actually return the parsed value, though that sounds like an unnecessary round trip to me. In your first answer you said that the query state cannot be set to errored, since the query function itself did not error, which is correct. But why couldn't |
You can either implement your own |
Implementing a custom |
Describe the bug
useSuspenseQuery
seems to have incorrect behavior whenselect
function throws an error. Right now if theselect
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.Expected behavior
useSuspenseQuery
should propagate errors being thrown fromselect
, just like when they are thrown fromqueryFn
.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
The text was updated successfully, but these errors were encountered: