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:
- Click “show projects”.
- Open one of the projects
- Go back to the list of projects
- Change
shouldThrowto true - Open a project again -> this should throw the error
- Change the
shouldThrowto false - 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)
Here is an example @TkDodo
https://github.com/talksik/rq-suspense-bug
Only looking at this file should do it: https://github.com/talksik/rq-suspense-bug/blob/master/src/App.tsx
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.
the ErrorBoundary is from react-error-boundary
Issue reproduced with
react-queryv3.12.0 andreact-error-boundaryv3.1.0.In the codesandbox example, a workaround is to manually remove the queries just before calling
resetErrorBoundary():This issue is weird because react-query seems to have a unit test to cover this use case.