useSuspenseQuery is awkward #6348
-
Hi) Till v5.7.2 I lived like a boss with useQuery and
cause I need to handle errors in my components, near any query usage. I have a lot of queries, where my backend can answer with an error. And this error can have a useful body. For example, 403 error with a description about restrictions. But, in 5.7.2 you've removed the <ErrorBoundary
FallbackComponent={(error) => <div>{JSON.stringify(error)}</div>}
>
<Suspense fallback={<Preloader />}>
<CompWithUseSuspenseQueryInside />
</Suspense>
</ErrorBoundary> Moreover, if I need a boundary reset, I have to wrap it with one more wrapper: Ok, it is a react way. So, I need to be adaptive. But it is so painful. It was like a charm, when we had And there is an interesting case. I have a query, which has I have to say, By the way, what if I want to render errors from my back and I do not want to refetch on client after SSR? I just can not imagine, how to implement it with So, the main question is — is it possible (or you have any ideas about it) to set |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
That's the intended API change for v5, yes.
that is correct. if you were to set
yes there is: https://tanstack.com/query/v5/docs/react/guides/suspense#throwonerror-default
This is easily abstractable into a
Yes, it's the react way. Suspense is an architectural change, not just a way to show a global loading spinner.
You can still use a
Again, this is how suspense is designed by react. If it fails to fetch on the server, it will render the fallback on the client and re-fetch there. Only if that fails, the error boundary will be shown. |
Beta Was this translation helpful? Give feedback.
-
@TkDodo sorry to bother you, but there are some strange things in
Actually, looks like that all is* flags (exceptions are isFetch* flags like isFetching and etc) are useless. Should we remove them from typings in
|
Beta Was this translation helpful? Give feedback.
queryFn
, it can't beundefined
- it has to benull
or something else. This is independent of suspense -undefined
is reserved for pending or error state, and we use it to bail out of state updates, too. It can't be used for a "successful" query.isPending
, have a fixed value, andstatus
is justsuccess
orerror
. Background refetches can still happen and they can also error, which means your query can be in error state and render accordingly. We think…