query: QueryErrorResetBoundary does not reset the state of the query

Describe the bug

QueryErrorResetBoundary does not seem to reset the query in suspense mode.

To Reproduce Steps to reproduce the behavior:

https://codesandbox.io/s/sweet-greider-edmen

It’s a slightly changed suspense example. I added a button that toggles a shouldThrow state. shouldThrow is passed to the Project component and based on its value, fetch function throws or fetches the data from API.

Steps to reproduce:

  1. Click “show projects”.
  2. Open one of the projects
  3. Go back to the list of projects
  4. Change shouldThrow to true
  5. Open a project again -> this should throw the error
  6. Change the shouldThrow to false
  7. Click “try again” -> this will throw again, but shouldn’t

Expected behavior After calling reset all queries nested in QueryErrorResetBoundary should be reset to some default state and they should try to fetch the data again.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Chrome
  • Version: latest

Smartphone (please complete the following information):

  • Device: iPhone X
  • OS: iOS 14
  • Browser: React-Native
  • Version: latest Expo

Additional context This happens in both react and react-native.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 15 (3 by maintainers)

Most upvoted comments

I am having the same issue, I started with useSuspenseQuery on my getUser hook (it gets the logged in user data from Auth0). During the login process, the users is undefined and it is being caught by the Error Boundary. I try to reset but it does not work for me. At least haven’t find the correct way yet.

<QueryErrorResetBoundary>
            {({ reset }) => (
                <ErrorBoundary
                    onReset={reset}

the ErrorBoundary is from react-error-boundary

Issue reproduced with react-query v3.12.0 and react-error-boundary v3.1.0.

In the codesandbox example, a workaround is to manually remove the queries just before calling resetErrorBoundary():

<Button
   onClick={async () => {
      await queryClient.removeQueries("project", {
        active: false
       });
       resetErrorBoundary();
    }}
>
    Try again
 </Button>

This issue is weird because react-query seems to have a unit test to cover this use case.