GeezerVison is showing github.com — Resolve default onRecoverableError at root init (#23264) · react/react@efd8f64
File treeExpand file treeCollapse file tree Open diff view settings react-native-renderer/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-art/src/ReactARTHostConfig.js -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -451,7 +451,3 @@ export function preparePortalMount(portalInstance: any): void { | 451 | 451 | export function detachDeletedInstance(node: Instance): void { | 452 | 452 | // noop | 453 | 453 | } | 454 | | - | 455 | | -export function logRecoverableError(error) { | 456 | | - // noop | 457 | | -} |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOMHostConfig.js -12Lines changed: 0 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -374,18 +374,6 @@ export function getCurrentEventPriority(): * { | 374 | 374 | return getEventPriority(currentEvent.type); | 375 | 375 | } | 376 | 376 |
| 377 | | -/* global reportError */ | 378 | | -export const logRecoverableError = | 379 | | - typeof reportError === 'function' | 380 | | - ? // In modern browsers, reportError will dispatch an error event, | 381 | | - // emulating an uncaught JavaScript error. | 382 | | - reportError | 383 | | - : (error: mixed) => { | 384 | | - // In older browsers and test environments, fallback to console.error. | 385 | | - // eslint-disable-next-line react-internal/no-production-logging, react-internal/warning-args | 386 | | - console.error(error); | 387 | | - }; | 388 | | - | 389 | 377 | export const isPrimaryRenderer = true; | 390 | 378 | export const warnsIfNotActing = true; | 391 | 379 | // This initialization code may run even on server environments | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOMLegacy.js +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -102,6 +102,11 @@ function getReactRootElementInContainer(container: any) { | 102 | 102 | } | 103 | 103 | } | 104 | 104 |
| | 105 | +function noopOnRecoverableError() { | | 106 | + // This isn't reachable because onRecoverableError isn't called in the | | 107 | + // legacy API. | | 108 | +} | | 109 | + | 105 | 110 | function legacyCreateRootFromDOMContainer( | 106 | 111 | container: Container, | 107 | 112 | forceHydrate: boolean, | @@ -122,7 +127,7 @@ function legacyCreateRootFromDOMContainer( | 122 | 127 | false, // isStrictMode | 123 | 128 | false, // concurrentUpdatesByDefaultOverride, | 124 | 129 | '', // identifierPrefix | 125 | | - null, | | 130 | + noopOnRecoverableError, | 126 | 131 | ); | 127 | 132 | markContainerAsRoot(root.current, container); | 128 | 133 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOMRoot.js +14-2Lines changed: 14 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -65,6 +65,18 @@ import { | 65 | 65 | import {ConcurrentRoot} from 'react-reconciler/src/ReactRootTags'; | 66 | 66 | import {allowConcurrentByDefault} from 'shared/ReactFeatureFlags'; | 67 | 67 |
| | 68 | +/* global reportError */ | | 69 | +const defaultOnRecoverableError = | | 70 | + typeof reportError === 'function' | | 71 | + ? // In modern browsers, reportError will dispatch an error event, | | 72 | + // emulating an uncaught JavaScript error. | | 73 | + reportError | | 74 | + : (error: mixed) => { | | 75 | + // In older browsers and test environments, fallback to console.error. | | 76 | + // eslint-disable-next-line react-internal/no-production-logging, react-internal/warning-args | | 77 | + console.error(error); | | 78 | + }; | | 79 | + | 68 | 80 | function ReactDOMRoot(internalRoot: FiberRoot) { | 69 | 81 | this._internalRoot = internalRoot; | 70 | 82 | } | @@ -145,7 +157,7 @@ export function createRoot( | 145 | 157 | let isStrictMode = false; | 146 | 158 | let concurrentUpdatesByDefaultOverride = false; | 147 | 159 | let identifierPrefix = ''; | 148 | | - let onRecoverableError = null; | | 160 | + let onRecoverableError = defaultOnRecoverableError; | 149 | 161 | if (options !== null && options !== undefined) { | 150 | 162 | if (__DEV__) { | 151 | 163 | if ((options: any).hydrate) { | @@ -220,7 +232,7 @@ export function hydrateRoot( | 220 | 232 | let isStrictMode = false; | 221 | 233 | let concurrentUpdatesByDefaultOverride = false; | 222 | 234 | let identifierPrefix = ''; | 223 | | - let onRecoverableError = null; | | 235 | + let onRecoverableError = defaultOnRecoverableError; | 224 | 236 | if (options !== null && options !== undefined) { | 225 | 237 | if (options.unstable_strictMode === true) { | 226 | 238 | isStrictMode = true; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFabric.js +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -195,6 +195,12 @@ function sendAccessibilityEvent(handle: any, eventType: string) { | 195 | 195 | } | 196 | 196 | } | 197 | 197 |
| | 198 | +function onRecoverableError(error) { | | 199 | + // TODO: Expose onRecoverableError option to userspace | | 200 | + // eslint-disable-next-line react-internal/no-production-logging, react-internal/warning-args | | 201 | + console.error(error); | | 202 | +} | | 203 | + | 198 | 204 | function render( | 199 | 205 | element: Element<ElementType>, | 200 | 206 | containerTag: number, | @@ -214,7 +220,7 @@ function render( | 214 | 220 | false, | 215 | 221 | null, | 216 | 222 | '', | 217 | | - null, | | 223 | + onRecoverableError, | 218 | 224 | ); | 219 | 225 | roots.set(containerTag, root); | 220 | 226 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFabricHostConfig.js -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -525,7 +525,3 @@ export function preparePortalMount(portalInstance: Instance): void { | 525 | 525 | export function detachDeletedInstance(node: Instance): void { | 526 | 526 | // noop | 527 | 527 | } | 528 | | - | 529 | | -export function logRecoverableError(error: mixed): void { | 530 | | - // noop | 531 | | -} |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeHostConfig.js -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -513,7 +513,3 @@ export function preparePortalMount(portalInstance: Instance): void { | 513 | 513 | export function detachDeletedInstance(node: Instance): void { | 514 | 514 | // noop | 515 | 515 | } | 516 | | - | 517 | | -export function logRecoverableError(error: mixed): void { | 518 | | - // noop | 519 | | -} |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeRenderer.js +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -192,6 +192,12 @@ function sendAccessibilityEvent(handle: any, eventType: string) { | 192 | 192 | } | 193 | 193 | } | 194 | 194 |
| | 195 | +function onRecoverableError(error) { | | 196 | + // TODO: Expose onRecoverableError option to userspace | | 197 | + // eslint-disable-next-line react-internal/no-production-logging, react-internal/warning-args | | 198 | + console.error(error); | | 199 | +} | | 200 | + | 195 | 201 | function render( | 196 | 202 | element: Element<ElementType>, | 197 | 203 | containerTag: number, | @@ -210,7 +216,7 @@ function render( | 210 | 216 | false, | 211 | 217 | null, | 212 | 218 | '', | 213 | | - null, | | 219 | + onRecoverableError, | 214 | 220 | ); | 215 | 221 | roots.set(containerTag, root); | 216 | 222 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-noop-renderer/src/createReactNoop.js +9-3Lines changed: 9 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -938,6 +938,12 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 938 | 938 | return NoopRenderer.flushSync(fn); | 939 | 939 | } | 940 | 940 |
| | 941 | + function onRecoverableError(error) { | | 942 | + // TODO: Turn this on once tests are fixed | | 943 | + // eslint-disable-next-line react-internal/no-production-logging, react-internal/warning-args | | 944 | + // console.error(error); | | 945 | + } | | 946 | + | 941 | 947 | let idCounter = 0; | 942 | 948 |
| 943 | 949 | const ReactNoop = { | @@ -966,7 +972,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 966 | 972 | null, | 967 | 973 | false, | 968 | 974 | '', | 969 | | - null, | | 975 | + onRecoverableError, | 970 | 976 | ); | 971 | 977 | roots.set(rootID, root); | 972 | 978 | } | @@ -988,7 +994,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 988 | 994 | null, | 989 | 995 | false, | 990 | 996 | '', | 991 | | - null, | | 997 | + onRecoverableError, | 992 | 998 | ); | 993 | 999 | return { | 994 | 1000 | _Scheduler: Scheduler, | @@ -1018,7 +1024,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 1018 | 1024 | null, | 1019 | 1025 | false, | 1020 | 1026 | '', | 1021 | | - null, | | 1027 | + onRecoverableError, | 1022 | 1028 | ); | 1023 | 1029 | return { | 1024 | 1030 | _Scheduler: Scheduler, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberReconciler.new.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -245,7 +245,7 @@ export function createContainer( | 245 | 245 | isStrictMode: boolean, | 246 | 246 | concurrentUpdatesByDefaultOverride: null | boolean, | 247 | 247 | identifierPrefix: string, | 248 | | - onRecoverableError: null | ((error: mixed) => void), | | 248 | + onRecoverableError: (error: mixed) => void, | 249 | 249 | ): OpaqueRoot { | 250 | 250 | return createFiberRoot( | 251 | 251 | containerInfo, | |
|