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
Replace catchRender with catchError #1742
Conversation
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.
This looks amazing, have you actually ever added a byte? 💯 You seem to solve errors and add features while losing bytes that's a talent if you ask me
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.
The master golfer has went it's course again 👍 Incredible work like usual 💯
This PR changes the behavior of the
catchError
option to enable composing of catchError option hooks (similar to middleware). The initial value ofoptions.catchError
is set tocatchErrorInComponent
. Any code that overridesoptions.catchError
should store the previous value ofoptions.catchError
and invoke it if they want to rely on the default implementation ofcatchError
. This pattern allows code to skip the default implementation of if an option hook chooses not to invoke the previous catchError behavior. It also gives options the ability to change what the default implementation is invoked with.Two new features this pattern enables:
In order to enable using
catchError
for Suspense, I had to change the behavior the ofcatchError
to take in the VNode that threw error, instead of the first parent. An initial implementation caused some problems in how errors were caught that our tests didn't catch so I modified some tests to cover this scenario. Namely, if a direct child of an error boundary throws, the error boundary should catch that error. The initial implementation was skipping the first parent if a child threw in unmount and refs.Change:
preact.js: -18 B
compat.js: -10 B