useSuspenseQuery do not throw when a "refetch" throws? #7585
Replies: 3 comments 6 replies
-
If you have data in the cache, even if its stale data, we will still render the component and not throw to the error boundary. That's on purpose because we believe stale data is better than no data - you get the same behaviour with throwing the error if it exists like shown is the best way if you really want that behaviour. |
Beta Was this translation helpful? Give feedback.
-
Hey @TkDodo thanks for the quick reply 🙏🏻 I could use your advices on how we can solve our use case. In one of our product, a user permissions (or even the feature flags of the product) could change at anytime. When the permission changes (or the feature flags), with a proprietary mecanism, the React application will re-render, but not go through a full browser refresh. When this happens, if a user is on a page that he doesn't have access to anymore, we will expect this user to be shown some type of "forbidden" error boundary. We expect that the page will figure out that the user cannot view it anymore by receiving a Now, of course we could handle this by throwing the We could wrap the Tanstack Query hooks and customize the behavior, but we would prefer avoiding doing this. Is there another option we could consider? Thank you, Patrick |
Beta Was this translation helpful? Give feedback.
-
I tried adding an const queryCache = new QueryCache({
onError: (error: Error) => {
if (isApiError(error) && error.status === 403) {
throw error;
}
}
});
const queryClient = new QueryClient({ queryCache });
export function QueryProvider({ children }: PropsWithChildren) {
return (
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
);
} When using If the page as already rendered sucessfully (meaning that the user is currently viewing the page), if a subsequent fetch returns a I am probably doing something wrong? |
Beta Was this translation helpful? Give feedback.
-
Hello!
I noticed that when using
useSuspenseQuery
, if the fetch request fails, an error is thrown. However, on a refetch, if the fetch request fails, it doesn't seems to throw. It does returns the error through theerror
prop though.So I could do:
But I was wondering if there's a way to configure this behavior with the default options of a
QueryClient
?Thank you,
Patrick
Beta Was this translation helpful? Give feedback.
All reactions