When using Suspense or throwOnError
, React Query never tries to refetch failed query
#8523
Labels
throwOnError
, React Query never tries to refetch failed query
#8523
Describe the bug
At Unsplash we have integrated React Query with SSR as per the official guide.
As per the guide, when a user performs a soft navigation from one route to another, we prefetch queries for the next route using
prefetchQuery
, in an event handler outside of React.Immediately after, route components render using the very same queries, with
useSuspenseQuery
. When this happens, React Query never attempts to run the query function again if the query failed at the previous prefetch step.Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-query-qkrlvsny?file=src%2Findex.tsx&preset=node
Steps to reproduce
prefetchQuery
.useSuspenseQuery
.Reduced test case here.
Another example of how this might happen is when we switch from one component to another, where both components use the same query. Reduced test case here.
Expected behavior
I would expect
queryFn
to run again when a new component tries to use the previously failed query for the first time, but it never does.React Query seems to retrieve the previous error from its cache. This error is then thrown, thus triggering the error boundary.
As per the docs on Resetting Error Boundaries, we could add a button to reset the query error and error boundary (updated test case here). However, ideally this wouldn't require an interaction from the user, and the query would automatically retry when its used for the first time in a component. This is the behaviour we have with
useQuery
.How often does this bug happen?
Often
Screenshots or Videos
No response
Platform
N/A
Tanstack Query adapter
None
TanStack Query version
5.63.0
TypeScript version
No response
Additional context
I think these issues are related, but I'm not familiar enough with React Query to know whether they're the same or slightly different:
useSuspenseQuery
does not retry afterfetchQuery
returned an error #7606The text was updated successfully, but these errors were encountered: