Skip to content

Commit a9f14cb

Browse files
authored
Fix Logging of Immediately Resolved Promises (#31610)
This avoid re-emitting the yellow "Event" log when we ping inside the original event. Instead of treating events as repeated when we get repeated updates, we treat them as repeated if we've ever logged out this event before. Additionally, in the case the prerender sibling flag is on we need to ensure that if a render gets interrupted when it has been suspended we treat that as "Prewarm" instead of "Interrupted Render". Before: <img width="539" alt="Screenshot 2024-11-19 at 2 39 44 PM" src="https://github.com/user-attachments/assets/190ca50c-5168-40d8-a6fd-6b9a583af1f0"> After: <img width="1004" alt="Screenshot 2024-11-21 at 4 53 16 PM" src="https://github.com/user-attachments/assets/0c441ada-1ed1-412c-8935-aaf040c25dfe">
1 parent c11c951 commit a9f14cb

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

packages/react-reconciler/src/ReactFiberWorkLoop.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ import {
265265
startProfilerTimer,
266266
stopProfilerTimerIfRunningAndRecordDuration,
267267
stopProfilerTimerIfRunningAndRecordIncompleteDuration,
268-
markUpdateAsRepeat,
269268
trackSuspendedTime,
270269
startYieldTimer,
271270
yieldStartTime,
@@ -927,6 +926,7 @@ export function performWorkOnRoot(
927926
// We've returned from yielding to the event loop. Let's log the time it took.
928927
const yieldEndTime = now();
929928
switch (yieldReason) {
929+
case SuspendedOnImmediate:
930930
case SuspendedOnData:
931931
logSuspendedYieldTime(yieldStartTime, yieldEndTime, yieldedFiber);
932932
break;
@@ -1009,7 +1009,6 @@ export function performWorkOnRoot(
10091009
setCurrentTrackFromLanes(lanes);
10101010
logInconsistentRender(renderStartTime, renderEndTime);
10111011
finalizeRender(lanes, renderEndTime);
1012-
markUpdateAsRepeat(lanes);
10131012
}
10141013
// A store was mutated in an interleaved event. Render again,
10151014
// synchronously, to block further mutations.
@@ -1036,7 +1035,6 @@ export function performWorkOnRoot(
10361035
setCurrentTrackFromLanes(lanes);
10371036
logErroredRenderPhase(renderStartTime, renderEndTime);
10381037
finalizeRender(lanes, renderEndTime);
1039-
markUpdateAsRepeat(lanes);
10401038
}
10411039
lanes = errorRetryLanes;
10421040
exitStatus = recoverFromConcurrentError(
@@ -1740,7 +1738,18 @@ function prepareFreshStack(root: FiberRoot, lanes: Lanes): Fiber {
17401738
previousRenderStartTime > 0
17411739
) {
17421740
setCurrentTrackFromLanes(workInProgressRootRenderLanes);
1743-
logInterruptedRenderPhase(previousRenderStartTime, renderStartTime);
1741+
if (
1742+
workInProgressRootExitStatus === RootSuspended ||
1743+
workInProgressRootExitStatus === RootSuspendedWithDelay
1744+
) {
1745+
// If the root was already suspended when it got interrupted and restarted,
1746+
// then this is considered a prewarm and not an interrupted render because
1747+
// we couldn't have shown anything anyway so it's not a bad thing that we
1748+
// got interrupted.
1749+
logSuspendedRenderPhase(previousRenderStartTime, renderStartTime);
1750+
} else {
1751+
logInterruptedRenderPhase(previousRenderStartTime, renderStartTime);
1752+
}
17441753
finalizeRender(workInProgressRootRenderLanes, renderStartTime);
17451754
}
17461755

packages/react-reconciler/src/ReactProfilerTimer.js

+20-22
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ export function startUpdateTimerByLane(lane: Lane): void {
8080
blockingUpdateTime = now();
8181
const newEventTime = resolveEventTimeStamp();
8282
const newEventType = resolveEventType();
83-
blockingEventIsRepeat =
84-
newEventTime === blockingEventTime &&
85-
newEventType === blockingEventType;
83+
if (
84+
newEventTime !== blockingEventTime ||
85+
newEventType !== blockingEventType
86+
) {
87+
blockingEventIsRepeat = false;
88+
}
8689
blockingEventTime = newEventTime;
8790
blockingEventType = newEventType;
8891
}
@@ -92,29 +95,19 @@ export function startUpdateTimerByLane(lane: Lane): void {
9295
if (transitionStartTime < 0) {
9396
const newEventTime = resolveEventTimeStamp();
9497
const newEventType = resolveEventType();
95-
transitionEventIsRepeat =
96-
newEventTime === transitionEventTime &&
97-
newEventType === transitionEventType;
98+
if (
99+
newEventTime !== transitionEventTime ||
100+
newEventType !== transitionEventType
101+
) {
102+
transitionEventIsRepeat = false;
103+
}
98104
transitionEventTime = newEventTime;
99105
transitionEventType = newEventType;
100106
}
101107
}
102108
}
103109
}
104110

105-
export function markUpdateAsRepeat(lanes: Lanes): void {
106-
if (!enableProfilerTimer || !enableComponentPerformanceTrack) {
107-
return;
108-
}
109-
// We're about to do a retry of this render. It is not a new update, so treat this
110-
// as a repeat within the same event.
111-
if (includesSyncLane(lanes) || includesBlockingLane(lanes)) {
112-
blockingEventIsRepeat = true;
113-
} else if (includesTransitionLane(lanes)) {
114-
transitionEventIsRepeat = true;
115-
}
116-
}
117-
118111
export function trackSuspendedTime(lanes: Lanes, renderEndTime: number) {
119112
if (!enableProfilerTimer || !enableComponentPerformanceTrack) {
120113
return;
@@ -129,6 +122,7 @@ export function trackSuspendedTime(lanes: Lanes, renderEndTime: number) {
129122
export function clearBlockingTimers(): void {
130123
blockingUpdateTime = -1.1;
131124
blockingSuspendedTime = -1.1;
125+
blockingEventIsRepeat = true;
132126
}
133127

134128
export function startAsyncTransitionTimer(): void {
@@ -139,9 +133,12 @@ export function startAsyncTransitionTimer(): void {
139133
transitionStartTime = now();
140134
const newEventTime = resolveEventTimeStamp();
141135
const newEventType = resolveEventType();
142-
transitionEventIsRepeat =
143-
newEventTime === transitionEventTime &&
144-
newEventType === transitionEventType;
136+
if (
137+
newEventTime !== transitionEventTime ||
138+
newEventType !== transitionEventType
139+
) {
140+
transitionEventIsRepeat = false;
141+
}
145142
transitionEventTime = newEventTime;
146143
transitionEventType = newEventType;
147144
}
@@ -173,6 +170,7 @@ export function clearTransitionTimers(): void {
173170
transitionStartTime = -1.1;
174171
transitionUpdateTime = -1.1;
175172
transitionSuspendedTime = -1.1;
173+
transitionEventIsRepeat = true;
176174
}
177175

178176
export function clampBlockingTimers(finalTime: number): void {

0 commit comments

Comments
 (0)