Move ReactFiberErrorDialog RN fork into RN itself (#16141)
Moti Zilberman committed
Jul 16, 2019 at 09:38 UTC
c45c2c3a261ab5a2878c36d9f49de531ef69a121
4 files changed
+26
-40
packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactFiberErrorDialog.js
new
+12
@@ -0,0 +1,12 @@
1
+/**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+module.exports = {
11
+ showErrorDialog: jest.fn(),
12
+};
packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js
+3
-3
@@ -11,15 +11,15 @@ module.exports = {
11
get BatchedBridge() {
12
return require('./BatchedBridge.js');
13
},
14
- get ExceptionsManager() {
15
- return require('./ExceptionsManager');
16
- },
14
get Platform() {
15
return require('./Platform');
16
},
17
get RCTEventEmitter() {
18
return require('./RCTEventEmitter');
19
},
20
+ get ReactFiberErrorDialog() {
21
+ return require('./ReactFiberErrorDialog');
22
+ },
23
get ReactNativeViewConfigRegistry() {
24
return require('./ReactNativeViewConfigRegistry');
25
},
packages/react-reconciler/src/forks/ReactFiberErrorDialog.native.js
+8
-35
@@ -10,41 +10,14 @@
10
import type {CapturedError} from '../ReactCapturedValue';
11
12
// Module provided by RN:
13
-import {ExceptionsManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
13
+import {ReactFiberErrorDialog as RNImpl} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
14
+import invariant from 'shared/invariant';
15
15
-/**
16
- * Intercept lifecycle errors and ensure they are shown with the correct stack
17
- * trace within the native redbox component.
18
- */
19
-export function showErrorDialog(capturedError: CapturedError): boolean {
20
- const {componentStack, error} = capturedError;
21
-
22
- let errorToHandle: Error;
23
-
24
- // Typically Errors are thrown but eg strings or null can be thrown as well.
25
- if (error instanceof Error) {
26
- const {message, name} = error;
16
+invariant(
17
+ typeof RNImpl.showErrorDialog === 'function',
18
+ 'Expected ReactFiberErrorDialog.showErrorDialog to be a function.',
19
+);
20
28
- const summary = message ? `${name}: ${message}` : name;
29
-
30
- errorToHandle = error;
31
-
32
- try {
33
- errorToHandle.message = `${summary}\n\nThis error is located at:${componentStack}`;
34
- } catch (e) {}
35
- } else if (typeof error === 'string') {
36
- errorToHandle = new Error(
37
- `${error}\n\nThis error is located at:${componentStack}`,
38
- );
39
- } else {
40
- errorToHandle = new Error(`Unspecified error at:${componentStack}`);
41
- }
42
-
43
- ExceptionsManager.handleException(errorToHandle, false);
44
-
45
- // Return false here to prevent ReactFiberErrorLogger default behavior of
46
- // logging error details to console.error. Calls to console.error are
47
- // automatically routed to the native redbox controller, which we've already
48
- // done above by calling ExceptionsManager.
49
- return false;
21
+export function showErrorDialog(capturedError: CapturedError): boolean {
22
+ return RNImpl.showErrorDialog(capturedError);
23
}
scripts/flow/react-native-host-hooks.js
+3
-2
@@ -17,6 +17,7 @@ import type {
17
ViewConfigGetter,
18
} from 'react-native-renderer/src/ReactNativeTypes';
19
import type {RNTopLevelEventType} from 'events/TopLevelEventTypes';
20
+import type {CapturedError} from 'react-reconciler/src/ReactCapturedValue';
21
22
declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' {
23
declare export function deepDiffer(one: any, two: any): boolean;
@@ -29,8 +30,8 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
30
blurTextInput: (object: any) => void,
31
focusTextInput: (object: any) => void,
32
};
32
- declare export var ExceptionsManager: {
33
- handleException: (error: Error, isFatal: boolean) => void,
33
+ declare export var ReactFiberErrorDialog: {
34
+ showErrorDialog: (error: CapturedError) => boolean,
35
};
36
declare export var Platform: {
37
OS: string,