Skip to content

Commit 79621b3

Browse files
committed
Mark commit phase as errored if there were any errors within
1 parent ead40b2 commit 79621b3

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

packages/react-reconciler/src/ReactFiberPerformanceTrack.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,56 @@ export function logSuspendedCommitPhase(
585585
}
586586
}
587587

588-
export function logCommitPhase(startTime: number, endTime: number): void {
588+
export function logCommitErrored(
589+
startTime: number,
590+
endTime: number,
591+
errors: Array<CapturedValue<mixed>>,
592+
passive: boolean,
593+
): void {
594+
if (supportsUserTiming) {
595+
const properties = [];
596+
if (__DEV__) {
597+
for (let i = 0; i < errors.length; i++) {
598+
const capturedValue = errors[i];
599+
const error = capturedValue.value;
600+
const message =
601+
typeof error === 'object' &&
602+
error !== null &&
603+
typeof error.message === 'string'
604+
? // eslint-disable-next-line react-internal/safe-string-coercion
605+
String(error.message)
606+
: // eslint-disable-next-line react-internal/safe-string-coercion
607+
String(error);
608+
properties.push(['Error', message]);
609+
}
610+
}
611+
performance.measure('Errored', {
612+
start: startTime,
613+
end: endTime,
614+
detail: {
615+
devtools: {
616+
color: 'error',
617+
track: reusableLaneDevToolDetails.track,
618+
trackGroup: LANES_TRACK_GROUP,
619+
tooltipText: passive
620+
? 'Commit Errored. See Components track.'
621+
: 'Effects Errored. See Components track.',
622+
properties,
623+
},
624+
},
625+
});
626+
}
627+
}
628+
629+
export function logCommitPhase(
630+
startTime: number,
631+
endTime: number,
632+
errors: null | Array<CapturedValue<mixed>>,
633+
): void {
634+
if (errors !== null) {
635+
logCommitErrored(startTime, endTime, errors, false);
636+
return;
637+
}
589638
if (supportsUserTiming) {
590639
reusableLaneDevToolDetails.color = 'secondary-dark';
591640
reusableLaneOptions.start = startTime;
@@ -613,7 +662,12 @@ export function logPaintYieldPhase(
613662
export function logPassiveCommitPhase(
614663
startTime: number,
615664
endTime: number,
665+
errors: null | Array<CapturedValue<mixed>>,
616666
): void {
667+
if (errors !== null) {
668+
logCommitErrored(startTime, endTime, errors, true);
669+
return;
670+
}
617671
if (supportsUserTiming) {
618672
reusableLaneDevToolDetails.color = 'secondary-dark';
619673
reusableLaneOptions.start = startTime;

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ import {
251251
renderStartTime,
252252
commitStartTime,
253253
commitEndTime,
254+
commitErrors,
254255
recordRenderTime,
255256
recordCommitTime,
256257
recordCommitEndTime,
@@ -263,6 +264,7 @@ import {
263264
yieldReason,
264265
startPingTimerByLanes,
265266
recordEffectError,
267+
resetCommitErrors,
266268
} from './ReactProfilerTimer';
267269

268270
// DEV stuff
@@ -3322,6 +3324,7 @@ function commitRootImpl(
33223324
if (enableProfilerTimer) {
33233325
// Mark the current commit time to be shared by all Profilers in this
33243326
// batch. This enables them to be grouped later.
3327+
resetCommitErrors();
33253328
recordCommitTime();
33263329
if (enableComponentPerformanceTrack) {
33273330
if (suspendedCommitReason === SUSPENDED_COMMIT) {
@@ -3415,6 +3418,7 @@ function commitRootImpl(
34153418
? completedRenderEndTime
34163419
: commitStartTime,
34173420
commitEndTime,
3421+
commitErrors,
34183422
);
34193423
}
34203424

@@ -3704,6 +3708,7 @@ function flushPassiveEffectsImpl(wasDelayedCommit: void | boolean) {
37043708

37053709
let passiveEffectStartTime = 0;
37063710
if (enableProfilerTimer && enableComponentPerformanceTrack) {
3711+
resetCommitErrors();
37073712
passiveEffectStartTime = now();
37083713
logPaintYieldPhase(
37093714
commitEndTime,
@@ -3740,7 +3745,11 @@ function flushPassiveEffectsImpl(wasDelayedCommit: void | boolean) {
37403745

37413746
if (enableProfilerTimer && enableComponentPerformanceTrack) {
37423747
const passiveEffectsEndTime = now();
3743-
logPassiveCommitPhase(passiveEffectStartTime, passiveEffectsEndTime);
3748+
logPassiveCommitPhase(
3749+
passiveEffectStartTime,
3750+
passiveEffectsEndTime,
3751+
commitErrors,
3752+
);
37443753
finalizeRender(lanes, passiveEffectsEndTime);
37453754
}
37463755

packages/react-reconciler/src/ReactProfilerTimer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const {unstable_now: now} = Scheduler;
4242
export let renderStartTime: number = -0;
4343
export let commitStartTime: number = -0;
4444
export let commitEndTime: number = -0;
45+
export let commitErrors: null | Array<CapturedValue<mixed>> = null;
4546
export let profilerStartTime: number = -1.1;
4647
export let profilerEffectDuration: number = -0;
4748
export let componentEffectDuration: number = -0;
@@ -429,10 +430,21 @@ export function recordEffectDuration(fiber: Fiber): void {
429430
}
430431

431432
export function recordEffectError(errorInfo: CapturedValue<mixed>): void {
433+
if (!enableProfilerTimer || !enableProfilerCommitHooks) {
434+
return;
435+
}
432436
if (componentEffectErrors === null) {
433437
componentEffectErrors = [];
434438
}
435439
componentEffectErrors.push(errorInfo);
440+
if (commitErrors === null) {
441+
commitErrors = [];
442+
}
443+
commitErrors.push(errorInfo);
444+
}
445+
446+
export function resetCommitErrors(): void {
447+
commitErrors = null;
436448
}
437449

438450
export function startEffectTimer(): void {

0 commit comments

Comments
 (0)