Skip to content

Commit 797927e

Browse files
committed
Use the stack trace of the errored Fiber instead of the Error Boundary
Ideally we'd show the whole failed subtree including the errored Component. We have the metrics for it. We just need to stash the Fibers somewhere. In the meantime we just change the stack trace of the error boundary entry.
1 parent e77b14f commit 797927e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/react-reconciler/src/ReactFiberPerformanceTrack.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,18 @@ export function logComponentErrored(
219219
// $FlowFixMe[method-unbinding]
220220
typeof performance.measure === 'function'
221221
) {
222+
let debugTask: ?ConsoleTask = null;
222223
const properties = [];
223224
for (let i = 0; i < errors.length; i++) {
224225
const capturedValue = errors[i];
226+
if (debugTask == null && capturedValue.source !== null) {
227+
// If the captured value has a source Fiber, use its debugTask for
228+
// the stack instead of the error boundary's stack. So you can find
229+
// which component errored since we don't show the errored render tree.
230+
// TODO: Ideally we should instead, store the failed fibers and log the
231+
// whole subtree including the component that errored.
232+
debugTask = capturedValue.source._debugTask;
233+
}
225234
const error = capturedValue.value;
226235
const message =
227236
typeof error === 'object' &&
@@ -233,6 +242,11 @@ export function logComponentErrored(
233242
String(error);
234243
properties.push(['Error', message]);
235244
}
245+
if (debugTask == null) {
246+
// If the captured values don't have a debug task, fallback to the
247+
// error boundary itself.
248+
debugTask = fiber._debugTask;
249+
}
236250
const options = {
237251
start: startTime,
238252
end: endTime,
@@ -248,7 +262,6 @@ export function logComponentErrored(
248262
},
249263
},
250264
};
251-
const debugTask = fiber._debugTask;
252265
if (__DEV__ && debugTask) {
253266
debugTask.run(
254267
// $FlowFixMe[method-unbinding]

0 commit comments

Comments
 (0)