-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
useQuery().promise
will always be a rejected promise if the query is in an error state
#8507
Comments
before you go to deep into this @KATT, I’m pretty sure query/packages/react-query/src/errorBoundaryUtils.ts Lines 29 to 38 in 74f0d6a
This could be wrong, but on the other hand, without that, we would never see an error boundary as we would attempt to refetch before it is ever shown. If we keep this behaviour, I think it’s fine to show the error from the error boundary, and then the boundary needs a “retry” button that also resets our flag as shown here: https://tanstack.com/query/latest/docs/framework/react/guides/suspense#resetting-error-boundaries |
Thank you! I'm glad I posted this issue before going too deep :) I wanted your thoughts before doing too much |
getOptimisticResult()
will always return an error state when it has previously erroreduseQuery().promise
will always be a rejected promise if the query is in an error state
Could you have a look at this test in #8508 and reaffirm that you also think that this should pass without futzing around with error boundaries? I'm just making sure there's an error in the cache: and trying to fetch it |
The way I'm thinking about it,
… must be a pending promise of the next result rather than the error & that it could either be done by a) futzing around with |
There are two things I’m seeing in your test:
|
Not exactly, that's why I didn't try to fix them together in #8501:
Conceptually, they can be solved together which is what a fix to this would likely look like
wdym? Are you saying prefetching in the test isn't good enough? |
Yeah, I’m just not sure why this is wrong 🤔 . If a query errors we expect it to show the error in an error boundary until the user has acknowledged that error. A prefetch doesn’t really change that?
I mean we need to split up the
by the time That’s why I said it’s conceptually similar to the enabled example |
Hm. Maybe this isn't a bug and aligns with how standard I just encountered it and expected it to refetch as it mounts even if it has errors in the cache. |
Describe the bug
If a query has ever errored,
getOptimisticResult()
will always return an error status (rather than a pending one)Your minimal, reproducible example
https://codesandbox.io/p/devbox/winter-darkness-k48yny
Steps to reproduce
useQuery().promise
somewhere elseExpected behavior
If the
getOptimisticResult()
should reflect the actual optimistic result, it should be pendingHow often does this bug happen?
None
Screenshots or Videos
No response
Platform
CodeSandbox
Tanstack Query adapter
None
TanStack Query version
latest
TypeScript version
latest
Additional context
Discovered while trying to fix #8499 and tried to fix in the same PR, but will try to have a stab on doing it separately
The text was updated successfully, but these errors were encountered: