Skip to content

Commit

Permalink
Also componentDidCatch
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Jul 23, 2024
1 parent 2e796ea commit 143febd
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/react-reconciler/src/ReactFiberCallUserSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,6 +52,7 @@ interface ClassInstance<R> {
prevState: Object,
snaphot: Object,
): void;
componentDidCatch(error: mixed, errorInfo: {componentStack: string}): void;
componentWillUnmount(): void;
}

Expand Down Expand Up @@ -125,6 +127,29 @@ export const callComponentDidUpdateInDEV: (
): any)
: (null: any);

const callComponentDidCatch = {
'react-stack-bottom-frame': function (
instance: ClassInstance<any>,
errorInfo: CapturedValue<mixed>,
): void {
const error = errorInfo.value;
const stack = errorInfo.stack;
instance.componentDidCatch(error, {
componentStack: stack !== null ? stack : '',
});
},
};

export const callComponentDidCatchInDEV: (
instance: ClassInstance<any>,
errorInfo: CapturedValue<mixed>,
) => 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,
Expand Down

0 comments on commit 143febd

Please sign in to comment.