Description
This is likely to cause some controversy so I’d love to hear the arguments against doing this.
I want to enable “red box” on any JavaScript error in development, similar to the proposal in facebook/react#1753. When an uncaught exception is thrown, an error is shown full screen similar to our syntax overlay (#744). It shows the error message and the stack. The full-screen message can be dismissed by pressing “Escape” in case you still want to interact with a broken app. The error is also printed in the console, like before.
We can use https://github.com/commissure/redbox-react although I’d prefer to have full control over this box in our monorepo to quickly patch bugs and improve the output.
Why I want to do this:
- React is currently not tolerant to errors thrown inside components. Its internal state often gets corrupted by this, so we want to surface errors early and prominently.
- We already do this on React Native to great success.
- In CRA we control the environment and we can do this.
- This is a part of my plan to bring hot reloading to CRA: Status/Roadmap of the project gaearon/react-hot-boilerplate#97 (comment).
Open questions:
- How to capture all errors with stacks in development. Does
window.onerror
provideError
objects in modern browsers now? - What to do about unhandled Promise rejections. Ideally we want to surface them given how common this problem and misunderstanding is.
- What do do about errors inside React that accidentally get caught, like No error is shown when use a undefined variable react#7617 (comment). Even if the code is technically valid, React just doesn’t support this pattern. Any error inside
setState()
orReactDOM.render()
is going to mess it up. We could monkey-patch them to report errors, or add some hooks in React itself to surface them.
Feedback and thoughts welcome.