Integration with react error boundaries #3322
timmy-wright
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
Here's a hack I did to wrap the observable method with some code to recover from errors. I really don't like it, but it appears to work:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
How would you solve this without Mobx? One simple thing we could probably do is to add the reaction to the error object. The ErrorBoundary can in principle introspect the reaction and subscribe for the same dependencies. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This has been asked a couple of times in the past, but I think I've got a good use case :)
Basically, on the odd occasion, our components throw errors that will be recoverable in time - once data has loaded from the server, etc. In an ideal world, the components would handle these errors, but our application is complex and programmers make mistakes. And we'd prefer if our application can recover from transient inconsistent states due to programmers making mistakes.
Anyway. If one of our react component does throw an error, we would like this to occur:
Currently, we have to wrap our components in an "ErrorBoundary" component (we wrote this). The way that react's error-boundary works is our component has a method called "componentDidCatch" that is passed the error. And our component either renders a nice pretty error message when that happens.
However, our component doesn't get callbacks from mobx to retry to render its children when the state changes - because mobx doesn't track what our components children use (as it shouldn't!). This means that once an error occurs, we don't retry to re-render children - even if our application has moved to a non-error state.
I can see two solutions to this:
There are prob other workarounds as well.
Here is a sample file that (hopefully) can reproduce the error. Typescript - I had to change the extension to .txt because github.
TestErrorBoundary.txt
Beta Was this translation helpful? Give feedback.
All reactions