Skip to content
Source
Sign inSign up
TanStack/query

useQueryErrorResetBoundary() does not resets errorneous useQueries() #4874

Send to my agent
Closedchekrd(GitHub profile, opens in a new tab) opened this issue 13 comments

Describe 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

  1. Go to https://codesandbox.io/s/bold-robinson-pu7zl2?file=/src/App.js
  2. Click the "Show component" button.
  3. Error boundary renders fallback (correct).
  4. Click the "Try again" button.
  5. 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

  1. is @TkDodo is anyone working on this I would like to work on this

  2. I talked to @chekrd to take a look because he filed the issue, but you can also take a look if you want. Thanks 🙏

  3. TkDodo added labelsgood first issue

  4. TkDodo added labelsbug

  5. TkDodo added labelspackage: react-query

  6. I did a little bit more research and things are as follows.

    • useQueries in 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 setting retryOnMount: false.
    • But retryOnMount: false seems to be the reason why the reset() doesn't trigger a refetch for useQueries. useQuery does not refetch when reset() is called with retryOnMount: false too, so I guess this is somehow intended (?)
    • useQuery with retryOnMount: true; suspense: truethrows, then reset() triggers a refetch, so I expect the same from useQueries.

    Tldr: I don’t know internal correlations, but fixing 4644 so it behaves like useQuery, should help (?)

  7. Thanks for the analysis. I agree that we should focus on fixing #4644 and then hopefully this would be fixed as a side-effect

  8. A fix for #4644 got merged, but the provided sandbox still seems to fail with the last version (4.29.3). @chekrd FYI

  9. @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: false from the useQueries options to make the error reset() work. So, the question is, should refetchOnMount: false affect the behavior of resetting the errors? I don't think so, because it is called explicitly so the error should be reset.

  10. 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 with retryOnMount: 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.

  11. Oh, exactly, refetchOnMount from my previous comment can be mapped to retryOnMount :D

  12. But still, I understand retryOnMount: false will not refetch on error on mount, but why the query is not refetched when the error was manually reset? Is this correct behavior?

  13. yes. When the error boundary is reset, it unmounts the error boundary component and re-mounts your component instead. The retryOnMount flag is then responsible to decide if you want a refetch now or not. I think with useErrorBoundary on, 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.

  14. TkDodo closed this

  15. closing this because it now works as expected in v4.29.3

  16. Just tried this but it still doesn’t work for me.

  17. @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.