preact-render-to-string
preact-render-to-string copied to clipboard
Adds support for `componentDidCatch()`
This does not include support for the info argument because preact's support for componentDidCatch() does not pass this argument (https://github.com/developit/preact/pull/819#issue-136629967)
Also includes 3 new tests.
This should resolve https://github.com/developit/preact-render-to-string/issues/64
This current implementation is incorrect per this documentation: https://reactjs.org/docs/react-component.html#error-boundaries
NOTE Error boundaries only catch errors in the components below them in the tree. An error boundary can’t catch an error within itself.
Updating the code, starting with the tests.
I have updated the tests to verify that the error is in fact being passed to componentDidCatch with c7aba79.
Just noticed the React docs seem to indicate they don't support componentDidCatch during SSR: https://reactjs.org/docs/error-boundaries.html
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 (https://github.com/developit/preact-render-to-string/pull/66/#issuecomment-464513856) ... 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 👍