Skip to content

Commit ebd1555

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 a3e2b11 commit ebd1555

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
@@ -238,9 +238,18 @@ export function logComponentErrored(
238238
// $FlowFixMe[method-unbinding]
239239
typeof performance.measure === 'function'
240240
) {
241+
let debugTask: ?ConsoleTask = null;
241242
const properties = [];
242243
for (let i = 0; i < errors.length; i++) {
243244
const capturedValue = errors[i];
245+
if (debugTask == null && capturedValue.source !== null) {
246+
// If the captured value has a source Fiber, use its debugTask for
247+
// the stack instead of the error boundary's stack. So you can find
248+
// which component errored since we don't show the errored render tree.
249+
// TODO: Ideally we should instead, store the failed fibers and log the
250+
// whole subtree including the component that errored.
251+
debugTask = capturedValue.source._debugTask;
252+
}
244253
const error = capturedValue.value;
245254
const message =
246255
typeof error === 'object' &&
@@ -252,6 +261,11 @@ export function logComponentErrored(
252261
String(error);
253262
properties.push(['Error', message]);
254263
}
264+
if (debugTask == null) {
265+
// If the captured values don't have a debug task, fallback to the
266+
// error boundary itself.
267+
debugTask = fiber._debugTask;
268+
}
255269
const options = {
256270
start: startTime,
257271
end: endTime,
@@ -267,7 +281,6 @@ export function logComponentErrored(
267281
},
268282
},
269283
};
270-
const debugTask = fiber._debugTask;
271284
if (__DEV__ && debugTask) {
272285
debugTask.run(
273286
// $FlowFixMe[method-unbinding]

0 commit comments

Comments
 (0)