|
10 | 10 | import type {Fiber} from './ReactInternalTypes';
|
11 | 11 | import type {LazyComponent} from 'react/src/ReactLazy';
|
12 | 12 | import type {Effect} from './ReactFiberHooks';
|
| 13 | +import type {CapturedValue} from './ReactCapturedValue'; |
13 | 14 |
|
14 | 15 | import {isRendering, setIsRendering} from './ReactCurrentFiber';
|
15 | 16 | import {captureCommitPhaseError} from './ReactFiberWorkLoop';
|
@@ -51,6 +52,7 @@ interface ClassInstance<R> {
|
51 | 52 | prevState: Object,
|
52 | 53 | snaphot: Object,
|
53 | 54 | ): void;
|
| 55 | + componentDidCatch(error: mixed, errorInfo: {componentStack: string}): void; |
54 | 56 | componentWillUnmount(): void;
|
55 | 57 | }
|
56 | 58 |
|
@@ -125,6 +127,29 @@ export const callComponentDidUpdateInDEV: (
|
125 | 127 | ): any)
|
126 | 128 | : (null: any);
|
127 | 129 |
|
| 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 | + |
128 | 153 | const callComponentWillUnmount = {
|
129 | 154 | 'react-stack-bottom-frame': function (
|
130 | 155 | current: Fiber,
|
|
0 commit comments