Skip to content

Commit 143febd

Browse files
committed
Also componentDidCatch
1 parent 2e796ea commit 143febd

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

packages/react-reconciler/src/ReactFiberCallUserSpace.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import type {Fiber} from './ReactInternalTypes';
1111
import type {LazyComponent} from 'react/src/ReactLazy';
1212
import type {Effect} from './ReactFiberHooks';
13+
import type {CapturedValue} from './ReactCapturedValue';
1314

1415
import {isRendering, setIsRendering} from './ReactCurrentFiber';
1516
import {captureCommitPhaseError} from './ReactFiberWorkLoop';
@@ -51,6 +52,7 @@ interface ClassInstance<R> {
5152
prevState: Object,
5253
snaphot: Object,
5354
): void;
55+
componentDidCatch(error: mixed, errorInfo: {componentStack: string}): void;
5456
componentWillUnmount(): void;
5557
}
5658

@@ -125,6 +127,29 @@ export const callComponentDidUpdateInDEV: (
125127
): any)
126128
: (null: any);
127129

130+
const callComponentDidCatch = {
131+
'react-stack-bottom-frame': function (
132+
instance: ClassInstance<any>,
133+
errorInfo: CapturedValue<mixed>,
134+
): void {
135+
const error = errorInfo.value;
136+
const stack = errorInfo.stack;
137+
instance.componentDidCatch(error, {
138+
componentStack: stack !== null ? stack : '',
139+
});
140+
},
141+
};
142+
143+
export const callComponentDidCatchInDEV: (
144+
instance: ClassInstance<any>,
145+
errorInfo: CapturedValue<mixed>,
146+
) => void = __DEV__
147+
? // We use this technique to trick minifiers to preserve the function name.
148+
(callComponentDidCatch['react-stack-bottom-frame'].bind(
149+
callComponentDidCatch,
150+
): any)
151+
: (null: any);
152+
128153
const callComponentWillUnmount = {
129154
'react-stack-bottom-frame': function (
130155
current: Fiber,

0 commit comments

Comments
 (0)