query: Errored queries caught by ErrorBoundary are not retried on mount

Describe the bug I’m using Suspense and ErrorBoundaries and I’m seeing unexpected behavior when queries are erroring. If a query errors I’m displaying an ErrorBoundary for that part of the UI. Now if I navigate to another page using react-router-dom and navigate back to the page, the ErrorBoundary is still there and the query is not retried. I know that normally you would have to reset the error boundary while you are on the same page to trigger a re-run of the failed queries, but in this case I would’ve assumed that the queries are retried when I visit the page again, i.e. the components are mounted again.

To Reproduce

  1. Visit the Code Sandbox
  2. Open the console
  3. Wait until the error occurs and the fallback of the ErrorBoundary is shown: “An error occured!” (You need to click off of react-error-overlay to see it)
  4. Press the “Hide” button to unmount the ErrorBoundary
  5. Press the “Show” button to render it again
  6. Query is not re-executed and the error is immediately shown again

Expected behavior The query is re-executed after the component mounts, i.e. honoring the retryOnMount setting.

Desktop (please complete the following information):

  • Version: 3.24.4

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 2
  • Comments: 26

Most upvoted comments

With retryOnMount set to true I was expecting that simply clearing the error state in a boundary thereby causing a remount of children would do the trick for retrying

I thought so too, but alas, it’s not that simple. In my mental modal, what should happen is:

  • throw error
  • error boundary renders
  • error boundary unmounts, children render, fetch again

what actually happens is:

  • throw error
  • component renders again (!)
  • then, error boundary renders

https://twitter.com/TkDodo/status/1624720921842925574

the component re-rendering again in error state is pretty problematic for us, because we would immediately refetch. I tried to work around that, but then it kind of screwed suspense. It’s pretty tricky.

Anyways, did my above solution with resetKeys not solve the issue?