Repository navigation
Conversation
4f0d3d0 to
4d1c761
Compare
2b4bf83 to
ee96497
Compare
|
I think we want to do a more general change here which should go through an RFC, to stop considering all uncaught errors (regardless of whether they come from React or not) as fatal. |
| render(): React.Node { | ||
| return this.state.hasError ? null : this.props.children; | ||
| } |
There was a problem hiding this comment.
This means that after an error, the app just blanks out, which is worse IMO than crashing.
|
Makes a lot of sense to me, you mentioned that before too. I'll set this as a draft. |
chrfalch
left a comment
There was a problem hiding this comment.
This change turns every render error under the root component from fatal into non-fatal, for every app, with no way to opt out. In development nothing visible changes, because LogBox already shows component errors as fatal. In a release build the effect is large. Today a fatal error makes iOS reload the bundle and then crash, and makes Android throw a JavascriptException, so crash reporters record it and the user gets a fresh start. With this boundary, the root view stays empty for the rest of the session: iOS only calls the soft-exception delegate, and Android only writes the error to the log. I would gate this behind a feature flag or a renderApplication option, and mark it as a breaking change in the changelog. The test also does not show that the boundary rendered nothing (see the inline comment).
ee96497 to
7585b38
Compare
|
The root error boundary now sits behind |
chrfalch
left a comment
There was a problem hiding this comment.
The boundary is now behind a flag that is off by default, and the test checks that the root View stays empty. Two small points remain: the flag's metadata says it is expected to become the default, and the test checks React's own log message instead of the non-fatal report that React Native sends.
Apps can enable `enableRootErrorBoundary` at startup to wrap the root component in an error boundary. If a React error reaches that boundary in a release build, the failed surface stays blank until the boundary is remounted, and React Native reports the error as non-fatal. The flag is an operational, per-app policy: both its default value and its expected release value are off, so uncaught React errors stay fatal in every app that does not opt in. `yarn jest --runInBand --runTestsByPath packages/react-native/Libraries/ReactNative/__tests__/renderApplication-test.js` verifies the empty root view, the non-fatal report from the caught-error handler that `renderApplication` passes to Fabric, and the default uncaught path. Each assertion fails when its behavior is removed. The remaining `Libraries/ReactNative` Jest tests, `yarn flow-check`, `yarn lint`, and `yarn format-check-javascript` pass. `yarn featureflags --update` leaves the generated files unchanged. Signed-off-by: James Ide <ide@expo.dev>
7585b38 to
cf12d40
Compare
|
Thanks, both points are addressed in the updated commit. |
Summary:
Apps can enable the JavaScript-only
enableRootErrorBoundaryflag at startup throughReactNativeFeatureFlags.overridefromreact-native/react-private-interface. This wraps the root component in an error boundary. If an error from rendering, a lifecycle method, or an effect reaches that boundary in a release build, React Native reports it as non-fatal and keeps the app running. The failed surface stays blank until the boundary is remounted.The flag is a per-app policy, and there is no plan to turn it on for every app. Both its default value and its
expectedReleaseValuearefalse, so a change to itsossReleaseStagedoes not turn the boundary on in apps that did not opt in. Its purpose isoperationalbecause it is meant to stay; onlyexperimentationflags carry adateAddedthat is used to prioritize their cleanup.With the flag off,
renderApplicationrenders the root component directly and React Native reports uncaught React errors as fatal. With the flag on, app error boundaries still handle errors within their own trees first, andWrapperComponentstays outside the root boundary.Changelog:
[GENERAL] [ADDED] - Add an opt-in root error boundary that leaves a failed surface blank and reports the error as non-fatal.
Test Plan:
yarn jest --runInBand --runTestsByPath packages/react-native/Libraries/ReactNative/__tests__/renderApplication-test.js yarn jest --runInBand packages/react-native/Libraries/ReactNative --testPathIgnorePatterns='/renderApplication-test\.js$' yarn flow-check yarn lint yarn format-check-javascript yarn featureflags --updateAll commands pass, and
yarn featureflags --updateleaves the generated files unchanged. With the flag on, the focused test checks that the production container's rootViewis empty, and that theonCaughtErrorhandlerrenderApplicationpasses toReactFabric.rendercallsExceptionsManager.handleException(error, false). The React test renderer does not accept error handlers, so the test calls that handler with the error itself. With the flag off, the test checks that the error stays uncaught. Each assertion fails when its behavior is removed: a non-empty boundary fallback, a fatal report fromonCaughtError,onUncaughtErrorpassed in its place, and the boundary forced on or off. The release reporting behavior was verified in the native sources. Device behavior was outside the test run.