-
-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds support for componentDidCatch()
#66
Conversation
…cause `preact`'s support for `componentDidCatch()` does not pass this argument (preactjs/preact#819 (comment))
This should resolve #64 |
This current implementation is incorrect per this documentation: https://reactjs.org/docs/react-component.html#error-boundaries
Updating the code, starting with the tests. |
I have updated the tests to verify that the error is in fact being passed to |
@@ -82,7 +83,17 @@ function renderToString(vnode, context, opts, inner, isSvgMode) { | |||
} | |||
} | |||
|
|||
return renderToString(rendered, context, opts, opts.shallowHighOrder!==false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea: we can circumvent having to catch and re-throw the error when there's no componentDidCatch:
if (c && c.componentDidCatch) {
try {
return renderToString(rendered, context, opts, opts.shallowHighOrder!==false);
}
catch (error) {
c.componentDidCatch(error);
rendered = c.render(c.props, c.state, c.context);
// now we fall through to the non-componentDidCatch render!
}
}
return renderToString(rendered, context, opts, opts.shallowHighOrder!==false);
Just noticed the React docs seem to indicate they don't support componentDidCatch during SSR: Are we early on this and risking breaking compat? |
/cc @andrewiggins |
One thing I think we might want to consider is extending this to also allow catching enqueued state updates. Something like "render the component, then check if it errored or was dirtied via setState()/forceUpdate(). If so, render again". |
per react's server support for error boundaries (#66) ... if react does not support it, then it probably is not right to support it |
I concur, this would be an awesome feature to support imo 👍 |
Closing as implemented in #305, upon the work done here. Thanks! |
This does not include support for the
info
argument becausepreact
's support forcomponentDidCatch()
does not pass this argument (preactjs/preact#819 (comment))Also includes 3 new tests.