Suspense + Mutate + ErrorBoundary #1797
Replies: 1 comment 3 replies
-
This is kinda tricky to consider — should a revalidation cause the component to throw and fallback to its boundary (Suspense or error boundary)? Due to the built-in cache of SWR, when a revalidation fails, I think that showing the stale data on the screen (not throwing and returning the error state like before), instead of falling back to the boundary, might lead to a better UX. Otherwise the component might fallback unexpectedly whenever e.g. user refocuses on the screen. But of course, if that’s inside a transition, then it’s not the case. Overall I feel that it’s pretty difficult to reason about the “stale-while-revalidate” model with suspense. A blurry idea in my head is to always wrap the internal revalidations with transitions. Maybe for now you can add |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to get an ErrorBoundary showing after a refetch via
mutate()
. If the initial request fails, the error boundary shows. If I make it so the initial request succeeds but then the next request fails, and try to use the boundmutate()
, the error boundary doesn't show (nor does its componentDidCatch hook run).I'll be able to put a simplified reproduction later but wanted to drop this in now to see if there's something I'm missing wrt to the expected behavior? I do want to keep the stale data rendered but was hoping for at least a
componentDidCatch()
so I could show a Toast UI that the feed wasn't able to refresh.Thanks for any tips!
Beta Was this translation helpful? Give feedback.
All reactions