Error boundaries
klarstrup opened this issue · 3 comments
Currently throwing in a component that is a descendant of a component with componentDidCatch
/getDerivedStateFromError
results in ssrPrepass
bailing entirely, that's a bit annoying and it feels like error boundaries are natural companions to Suspense("promise boundaries)".
Is this something worth putting effort into trying to support?
That's a good shout. The problem with that is that currently react-ssr-prepass
isn't really set up to bail and reenter the element tree at a higher level.
So that'd require quite some big changes. I'd imagine that the lowest effort fix would be to track the closest error boundary, so one at a time and to fall back on that if necessary.
Another alternative would be to not interrupt rendering at all on any kind of errors.
I've thought about this a little more and I don't think we'll implement this for two reasons:
react-ssr-prepass
is only a prepass so you can await on it and catch the error and ignore it, because it's mostly meant to just fetch suspense data and assume that data has been fetched afterwards, not for full rendering.react-ssr-prepass
is more or less temporary until React implements all aspects of Suspense fetching on the server-side, so our hope is it'll eventually go away, which is why this is another reason of it not being a full renderer.
Lastly, I think it's safe to assume that you can catch the error from prepass and resume rendering in react-dom/server
regardless of what has happened.
Reopening since I believe I'm wrong and started working on this 😅
As more libraries implement Suspense APIs I can now see that a lot of them make use of suspending on fetching data that will ultimately reject. Furthermore I don't think it's completely unbelievable for some of these errors to be cached and subsequently thrown again on the client-side, which may also mean that people will rely on some Suspense logic inside of error boundaries' fallbacks.