useQueryErrorResetBoundary() does not resets errorneous useQueries() #4874
Send to my agentDescribe the bug#
With useQuery, reset callback runs failed query again. With useQueries nothing happens and the error boundary fallback is unmounted.
Your minimal, reproducible example#
https://codesandbox.io/s/bold-robinson-pu7zl2?file=/src/App.js
Steps to reproduce#
- Go to https://codesandbox.io/s/bold-robinson-pu7zl2?file=/src/App.js
- Click the "Show component" button.
- Error boundary renders fallback (correct).
- Click the "Try again" button.
- The query is not reset. Also, ErrorBoundary stops rendering the fallback.
You can comment out line 22 and uncomment line 20 for comparison with useQuery. UseQuery correctly resets and fetches again.
Expected behavior#
useQuery and useQueries both should reset erroneous queries when reset() is called.
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
Platform independent
TanStack Query version#
4.22.4
TypeScript version#
No response
Additional context#
No response
I talked to @chekrd to take a look because he filed the issue, but you can also take a look if you want. Thanks 🙏
TkDodo added labelsgood first issue
TkDodo added labelsbug
TkDodo added labelspackage: react-query
I did a little bit more research and things are as follows.
useQueriesin Suspense mode does not throw for ErrorBoundary, it fetches in a loop instead. This is a known issue (https://github.com/TanStack/query/issues/4644). The recommended fix was settingretryOnMount: false.- But
retryOnMount: falseseems to be the reason why thereset()doesn't trigger a refetch foruseQueries.useQuerydoes not refetch whenreset()is called withretryOnMount: falsetoo, so I guess this is somehow intended (?) useQuerywithretryOnMount: true; suspense: truethrows, thenreset()triggers a refetch, so I expect the same fromuseQueries.
Tldr: I don’t know internal correlations, but fixing 4644 so it behaves like
useQuery, should help (?)@TkDodo I have updated my example and it seems to be working now (try again with this link: https://codesandbox.io/s/dawn-sound-cgzd86?file=/src/App.js ). I had to remove
refetchOnMount: falsefrom the useQueries options to make the error reset() work. So, the question is, shouldrefetchOnMount: falseaffect the behavior of resetting the errors? I don't think so, because it is called explicitly so the error should be reset.thanks @chekrd, it still works fine for me even if I set
refetchOnMount: false, because you are right, that flag should have no impact. Maybe you are confusing it withretryOnMount: false, because that does have an impact, from the docs:retryOnMount: boolean
If set to false, the query will not be retried on mount if it contains an error. Defaults to true.
Oh, exactly,
refetchOnMountfrom my previous comment can be mapped toretryOnMount:DBut still, I understand
retryOnMount: falsewill not refetch on error on mount, but why the query is not refetched when the error was manually reset? Is this correct behavior?yes. When the error boundary is reset, it unmounts the error boundary component and re-mounts your component instead. The
retryOnMountflag is then responsible to decide if you want a refetch now or not. I think withuseErrorBoundaryon, you'd better not want to set that flag to false. However, we also need to flip that internally when suspense is on, due to suspense also unmounting your component. It's weird, and will hopefully get better when maybe moving suspense to a dedicated hook.TkDodo closed this
closing this because it now works as expected in
v4.29.3Just tried this but it still doesn’t work for me.
@marklanham my code example is gone and I don't have time to try it in the following weeks. Would you create an example pls?
Sign in to join this conversation.
is @TkDodo is anyone working on this I would like to work on this