diff --git a/packages/react-reconciler/src/ReactFiberCallUserSpace.js b/packages/react-reconciler/src/ReactFiberCallUserSpace.js index 39b8d0543d1be..ada092438a5f0 100644 --- a/packages/react-reconciler/src/ReactFiberCallUserSpace.js +++ b/packages/react-reconciler/src/ReactFiberCallUserSpace.js @@ -10,6 +10,7 @@ import type {Fiber} from './ReactInternalTypes'; import type {LazyComponent} from 'react/src/ReactLazy'; import type {Effect} from './ReactFiberHooks'; +import type {CapturedValue} from './ReactCapturedValue'; import {isRendering, setIsRendering} from './ReactCurrentFiber'; import {captureCommitPhaseError} from './ReactFiberWorkLoop'; @@ -51,6 +52,7 @@ interface ClassInstance { prevState: Object, snaphot: Object, ): void; + componentDidCatch(error: mixed, errorInfo: {componentStack: string}): void; componentWillUnmount(): void; } @@ -125,6 +127,29 @@ export const callComponentDidUpdateInDEV: ( ): any) : (null: any); +const callComponentDidCatch = { + 'react-stack-bottom-frame': function ( + instance: ClassInstance, + errorInfo: CapturedValue, + ): void { + const error = errorInfo.value; + const stack = errorInfo.stack; + instance.componentDidCatch(error, { + componentStack: stack !== null ? stack : '', + }); + }, +}; + +export const callComponentDidCatchInDEV: ( + instance: ClassInstance, + errorInfo: CapturedValue, +) => void = __DEV__ + ? // We use this technique to trick minifiers to preserve the function name. + (callComponentDidCatch['react-stack-bottom-frame'].bind( + callComponentDidCatch, + ): any) + : (null: any); + const callComponentWillUnmount = { 'react-stack-bottom-frame': function ( current: Fiber,