-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useSuspenseQuery
does not retry failed queries even in new components
#11660
Comments
Hey @jbachhardie 👋 This is an interesting! Playing around a bit more with your reproduction, I'm actually not sure this is an issue with Digging in, there are a few things I noticed here though: The route components are never rendered again once the error occurs. While the error message is properly updated in the UI according to the route you're on, the route component functions aren't called again. I added This led me to think that the I'm able to fix the issue by adding a I added some comments in my fork for you to follow if you want to see this working as you'd expect.
Just a note on why the In order to avoid issues with Just as an FYI, we have a section on our docs for query call to call this out in case you needed a reference to it 🙂. I'm not sure there is actually anything for us to do here. Please let me know if I've missed something. Hope this helps! |
I should have also mentioned, you can use the See the error handling section in our suspense docs for more information on this. |
Hey, thank you so much for the thorough reply. I went back and made another attempt at reproduction that more closely zoomed in on the issue and directly compared suspense and non-suspense versions. I discovered that in fact Sorry for the bother but happy to have confirmed this all works as intended and that our approach to error handling with Suspense wasn't misguided. |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
No problem at all! Glad to hear everything is working as expected 🙂 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue Description
When
useQuery
returns an error, subsequent components usinguseQuery
will see that data hasn't been loaded for that query and try fetching from the server again.useSuspenseQuery
doesn't have this behaviour, instead every instance ofuseSuspenseQuery
for that query+variables will throw an error untilrefetch
is invoked.This is particularly noticeable and frustrating in two cases:
react-error-boundary
system of resetting the boundary to retry loading doesn't work. Instead, every query used inside the boundary needs to be converted into auseBackgroundQuery
prefetch so that we can pass refetch calls to the error boundary. This is a lot of extra steps for something that is going to have to be done literally everywhere and it means we can't e.g. have a generic error boundary that works for any page.Link to Reproduction
https://codesandbox.io/p/devbox/empty-snow-dw63kx?file=%2Fsrc%2Findex.jsx%3A27%2C15&workspaceId=03104bf9-16b8-430d-a030-08b693449298
Reproduction Steps
The Codesandbox simulates a situation where every second request fails. When a request does fail, you can see that navigating to a different page that uses the same query still errors. If you change the code to use
useQuery
instead you can see that it instead retries until a request succeeds as you navigate.@apollo/client
version3.9.6
The text was updated successfully, but these errors were encountered: