GeezerVison is showing github.com — Add on(Caught|Uncaught|Recoverable) opts to RN (#28836) · react/react@0347fcd
File treeExpand file treeCollapse file tree Open diff view settings packages/react-native-renderer/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFabric.js +39-3Lines changed: 39 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -101,11 +101,30 @@ function nativeOnCaughtError( | 101 | 101 | defaultOnCaughtError(error, errorInfo); | 102 | 102 | } | 103 | 103 |
| | 104 | +type NativeRenderOptions = { | | 105 | + onUncaughtError?: ( | | 106 | + error: mixed, | | 107 | + errorInfo: {+componentStack?: ?string}, | | 108 | + ) => void, | | 109 | + onCaughtError?: ( | | 110 | + error: mixed, | | 111 | + errorInfo: { | | 112 | + +componentStack?: ?string, | | 113 | + +errorBoundary?: ?React$Component<any, any>, | | 114 | + }, | | 115 | + ) => void, | | 116 | + onRecoverableError?: ( | | 117 | + error: mixed, | | 118 | + errorInfo: {+componentStack?: ?string}, | | 119 | + ) => void, | | 120 | +}; | | 121 | + | 104 | 122 | function render( | 105 | 123 | element: Element<ElementType>, | 106 | 124 | containerTag: number, | 107 | 125 | callback: ?() => void, | 108 | 126 | concurrentRoot: ?boolean, | | 127 | + options?: NativeRenderOptions, | 109 | 128 | ): ?ElementRef<ElementType> { | 110 | 129 | if (disableLegacyMode && !concurrentRoot) { | 111 | 130 | throw new Error('render: Unsupported Legacy Mode API.'); | @@ -114,6 +133,23 @@ function render( | 114 | 133 | let root = roots.get(containerTag); | 115 | 134 |
| 116 | 135 | if (!root) { | | 136 | + // TODO: these defaults are for backwards compatibility. | | 137 | + // Once RN implements these options internally, | | 138 | + // we can remove the defaults and ReactFiberErrorDialog. | | 139 | + let onUncaughtError = nativeOnUncaughtError; | | 140 | + let onCaughtError = nativeOnCaughtError; | | 141 | + let onRecoverableError = defaultOnRecoverableError; | | 142 | + | | 143 | + if (options && options.onUncaughtError !== undefined) { | | 144 | + onUncaughtError = options.onUncaughtError; | | 145 | + } | | 146 | + if (options && options.onCaughtError !== undefined) { | | 147 | + onCaughtError = options.onCaughtError; | | 148 | + } | | 149 | + if (options && options.onRecoverableError !== undefined) { | | 150 | + onRecoverableError = options.onRecoverableError; | | 151 | + } | | 152 | + | 117 | 153 | // TODO (bvaughn): If we decide to keep the wrapper component, | 118 | 154 | // We could create a wrapper for containerTag as well to reduce special casing. | 119 | 155 | root = createContainer( | @@ -123,9 +159,9 @@ function render( | 123 | 159 | false, | 124 | 160 | null, | 125 | 161 | '', | 126 | | - nativeOnUncaughtError, | 127 | | - nativeOnCaughtError, | 128 | | - defaultOnRecoverableError, | | 162 | + onUncaughtError, | | 163 | + onCaughtError, | | 164 | + onRecoverableError, | 129 | 165 | null, | 130 | 166 | ); | 131 | 167 | roots.set(containerTag, root); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeRenderer.js +39-3Lines changed: 39 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -106,10 +106,29 @@ function nativeOnCaughtError( | 106 | 106 | defaultOnCaughtError(error, errorInfo); | 107 | 107 | } | 108 | 108 |
| | 109 | +type NativeRenderOptions = { | | 110 | + onUncaughtError?: ( | | 111 | + error: mixed, | | 112 | + errorInfo: {+componentStack?: ?string}, | | 113 | + ) => void, | | 114 | + onCaughtError?: ( | | 115 | + error: mixed, | | 116 | + errorInfo: { | | 117 | + +componentStack?: ?string, | | 118 | + +errorBoundary?: ?React$Component<any, any>, | | 119 | + }, | | 120 | + ) => void, | | 121 | + onRecoverableError?: ( | | 122 | + error: mixed, | | 123 | + errorInfo: {+componentStack?: ?string}, | | 124 | + ) => void, | | 125 | +}; | | 126 | + | 109 | 127 | function render( | 110 | 128 | element: Element<ElementType>, | 111 | 129 | containerTag: number, | 112 | 130 | callback: ?() => void, | | 131 | + options?: NativeRenderOptions, | 113 | 132 | ): ?ElementRef<ElementType> { | 114 | 133 | if (disableLegacyMode) { | 115 | 134 | throw new Error('render: Unsupported Legacy Mode API.'); | @@ -118,6 +137,23 @@ function render( | 118 | 137 | let root = roots.get(containerTag); | 119 | 138 |
| 120 | 139 | if (!root) { | | 140 | + // TODO: these defaults are for backwards compatibility. | | 141 | + // Once RN implements these options internally, | | 142 | + // we can remove the defaults and ReactFiberErrorDialog. | | 143 | + let onUncaughtError = nativeOnUncaughtError; | | 144 | + let onCaughtError = nativeOnCaughtError; | | 145 | + let onRecoverableError = defaultOnRecoverableError; | | 146 | + | | 147 | + if (options && options.onUncaughtError !== undefined) { | | 148 | + onUncaughtError = options.onUncaughtError; | | 149 | + } | | 150 | + if (options && options.onCaughtError !== undefined) { | | 151 | + onCaughtError = options.onCaughtError; | | 152 | + } | | 153 | + if (options && options.onRecoverableError !== undefined) { | | 154 | + onRecoverableError = options.onRecoverableError; | | 155 | + } | | 156 | + | 121 | 157 | // TODO (bvaughn): If we decide to keep the wrapper component, | 122 | 158 | // We could create a wrapper for containerTag as well to reduce special casing. | 123 | 159 | root = createContainer( | @@ -127,9 +163,9 @@ function render( | 127 | 163 | false, | 128 | 164 | null, | 129 | 165 | '', | 130 | | - nativeOnUncaughtError, | 131 | | - nativeOnCaughtError, | 132 | | - defaultOnRecoverableError, | | 166 | + onUncaughtError, | | 167 | + onCaughtError, | | 168 | + onRecoverableError, | 133 | 169 | null, | 134 | 170 | ); | 135 | 171 | roots.set(containerTag, root); | |
|