preact-render-to-string icon indicating copy to clipboard operation
preact-render-to-string copied to clipboard

Adds support for `componentDidCatch()`

Open johnhaitas opened this issue 7 years ago • 8 comments

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.

johnhaitas avatar Nov 02 '18 18:11 johnhaitas

This should resolve https://github.com/developit/preact-render-to-string/issues/64

johnhaitas avatar Nov 02 '18 18:11 johnhaitas

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.

johnhaitas avatar Nov 02 '18 19:11 johnhaitas

I have updated the tests to verify that the error is in fact being passed to componentDidCatch with c7aba79.

johnhaitas avatar Nov 03 '18 14:11 johnhaitas

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?

developit avatar Feb 17 '19 21:02 developit

/cc @andrewiggins

developit avatar Feb 17 '19 21:02 developit

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".

developit avatar Mar 07 '19 15:03 developit

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

johnhaitas avatar Mar 07 '19 16:03 johnhaitas

I concur, this would be an awesome feature to support imo 👍

marvinhagemeister avatar Mar 07 '19 16:03 marvinhagemeister