diff --git a/packages/react-native-renderer/src/ReactFabric.js b/packages/react-native-renderer/src/ReactFabric.js index 2f534013aa2e6..78e65c1c0a26f 100644 --- a/packages/react-native-renderer/src/ReactFabric.js +++ b/packages/react-native-renderer/src/ReactFabric.js @@ -101,11 +101,30 @@ function nativeOnCaughtError( defaultOnCaughtError(error, errorInfo); } +type NativeRenderOptions = { + onUncaughtError?: ( + error: mixed, + errorInfo: {+componentStack?: ?string}, + ) => void, + onCaughtError?: ( + error: mixed, + errorInfo: { + +componentStack?: ?string, + +errorBoundary?: ?React$Component, + }, + ) => void, + onRecoverableError?: ( + error: mixed, + errorInfo: {+componentStack?: ?string}, + ) => void, +}; + function render( element: Element, containerTag: number, callback: ?() => void, concurrentRoot: ?boolean, + options?: NativeRenderOptions, ): ?ElementRef { if (disableLegacyMode && !concurrentRoot) { throw new Error('render: Unsupported Legacy Mode API.'); @@ -114,6 +133,23 @@ function render( let root = roots.get(containerTag); if (!root) { + // TODO: these defaults are for backwards compatibility. + // Once RN implements these options internally, + // we can remove the defaults and ReactFiberErrorDialog. + let onUncaughtError = nativeOnUncaughtError; + let onCaughtError = nativeOnCaughtError; + let onRecoverableError = defaultOnRecoverableError; + + if (options && options.onUncaughtError !== undefined) { + onUncaughtError = options.onUncaughtError; + } + if (options && options.onCaughtError !== undefined) { + onCaughtError = options.onCaughtError; + } + if (options && options.onRecoverableError !== undefined) { + onRecoverableError = options.onRecoverableError; + } + // TODO (bvaughn): If we decide to keep the wrapper component, // We could create a wrapper for containerTag as well to reduce special casing. root = createContainer( @@ -123,9 +159,9 @@ function render( false, null, '', - nativeOnUncaughtError, - nativeOnCaughtError, - defaultOnRecoverableError, + onUncaughtError, + onCaughtError, + onRecoverableError, null, ); roots.set(containerTag, root); diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 7c5410cfe4473..e7fb09d0d8ddc 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -106,10 +106,29 @@ function nativeOnCaughtError( defaultOnCaughtError(error, errorInfo); } +type NativeRenderOptions = { + onUncaughtError?: ( + error: mixed, + errorInfo: {+componentStack?: ?string}, + ) => void, + onCaughtError?: ( + error: mixed, + errorInfo: { + +componentStack?: ?string, + +errorBoundary?: ?React$Component, + }, + ) => void, + onRecoverableError?: ( + error: mixed, + errorInfo: {+componentStack?: ?string}, + ) => void, +}; + function render( element: Element, containerTag: number, callback: ?() => void, + options?: NativeRenderOptions, ): ?ElementRef { if (disableLegacyMode) { throw new Error('render: Unsupported Legacy Mode API.'); @@ -118,6 +137,23 @@ function render( let root = roots.get(containerTag); if (!root) { + // TODO: these defaults are for backwards compatibility. + // Once RN implements these options internally, + // we can remove the defaults and ReactFiberErrorDialog. + let onUncaughtError = nativeOnUncaughtError; + let onCaughtError = nativeOnCaughtError; + let onRecoverableError = defaultOnRecoverableError; + + if (options && options.onUncaughtError !== undefined) { + onUncaughtError = options.onUncaughtError; + } + if (options && options.onCaughtError !== undefined) { + onCaughtError = options.onCaughtError; + } + if (options && options.onRecoverableError !== undefined) { + onRecoverableError = options.onRecoverableError; + } + // TODO (bvaughn): If we decide to keep the wrapper component, // We could create a wrapper for containerTag as well to reduce special casing. root = createContainer( @@ -127,9 +163,9 @@ function render( false, null, '', - nativeOnUncaughtError, - nativeOnCaughtError, - defaultOnRecoverableError, + onUncaughtError, + onCaughtError, + onRecoverableError, null, ); roots.set(containerTag, root);