Commit c13986d

Browse files
authored
Fix Overlapping "message" Bug in Performance Track (#31528)
When you schedule a microtask from render or effect and then call setState (or ping) from there, the "event" is the event that React scheduled (which will be a postMessage). The event time of this new render will be before the last render finished. We usually clamp these but in this scenario the update doesn't happen while a render is happening. Causing overlapping events. Before: <img width="1229" alt="Screenshot 2024-11-12 at 11 01 30 PM" src="https://github.com/user-attachments/assets/9652cf3b-b358-453c-b295-1239cbb15952"> Therefore when we finalize a render we need to store the end of the last render so when we a new update comes in later with an event time earlier than that, we know to clamp it. There's also a special case here where when we enter the `RootDidNotComplete` or `RootSuspendedWithDelay` case we neither leave the root as in progress nor commit it. Those needs to finalize too. Really this should be modeled as a suspended track that we haven't added yet. That's the gap between "Blocked" and "message" below. After: <img width="1471" alt="Screenshot 2024-11-13 at 12 31 34 AM" src="https://github.com/user-attachments/assets/b24f994e-9055-4b10-ad29-ad9b36302ffc"> I also fixed an issue where we may log the same event name multiple times if we're rendering more than once in the same event. In this case I just leave a blank trace between the last commit and the next update. I also adding ignoring of the "message" event at all in these cases when the event is from React's scheduling itself.
1 parent 4686872 commit c13986d

12 files changed

Lines changed: 97 additions & 31 deletions

File tree

‎packages/react-art/src/ReactFiberConfigART.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ export function resolveUpdatePriority(): EventPriority {
363363
returncurrentUpdatePriority||DefaultEventPriority;
364364
}
365365

366+
exportfunctiontrackSchedulerEvent(): void{}
367+
366368
export functionresolveEventType(): null|string{
367369
returnnull;
368370
}

‎packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,19 @@ export function shouldAttemptEagerTransition(): boolean {
606606
returnfalse;
607607
}
608608

609+
letschedulerEvent: void|Event=undefined;
610+
exportfunctiontrackSchedulerEvent(): void{
611+
schedulerEvent=window.event;
612+
}
613+
609614
export functionresolveEventType(): null|string{
610615
constevent=window.event;
611-
returnevent ? event.type : null;
616+
returnevent&&event!==schedulerEvent? event.type : null;
612617
}
613618

614619
exportfunctionresolveEventTimeStamp(): number{
615620
constevent=window.event;
616-
returnevent ? event.timeStamp : -1.1;
621+
returnevent&&event!==schedulerEvent? event.timeStamp : -1.1;
617622
}
618623

619624
exportconstisPrimaryRenderer=true;

‎packages/react-native-renderer/src/ReactFiberConfigFabric.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ export function resolveUpdatePriority(): EventPriority {
372372
returnDefaultEventPriority;
373373
}
374374

375+
exportfunctiontrackSchedulerEvent(): void{}
376+
375377
export functionresolveEventType(): null|string{
376378
returnnull;
377379
}

‎packages/react-native-renderer/src/ReactFiberConfigNative.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ export function resolveUpdatePriority(): EventPriority {
288288
returnDefaultEventPriority;
289289
}
290290

291+
exportfunctiontrackSchedulerEvent(): void{}
292+
291293
export functionresolveEventType(): null|string{
292294
returnnull;
293295
}

‎packages/react-noop-renderer/src/createReactNoop.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
531531
returncurrentEventPriority;
532532
},
533533

534+
trackSchedulerEvent(): void{},
535+
534536
resolveEventType(): null|string{
535537
return null;
536538
},

‎packages/react-reconciler/src/ReactFiberPerformanceTrack.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export function logBlockingStart(
118118
updateTime: number,
119119
eventTime: number,
120120
eventType: null|string,
121+
eventIsRepeat: boolean,
121122
renderStartTime: number,
122123
): void{
123124
if(supportsUserTiming){
@@ -127,7 +128,7 @@ export function logBlockingStart(
127128
reusableLaneDevToolDetails.color='secondary-dark';
128129
reusableLaneOptions.start=eventTime;
129130
reusableLaneOptions.end=updateTime>0 ? updateTime : renderStartTime;
130-
performance.measure(eventType,reusableLaneOptions);
131+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
131132
}
132133
if(updateTime>0){
133134
// Log the time from when we called setState until we started rendering.
@@ -144,6 +145,7 @@ export function logTransitionStart(
144145
updateTime: number,
145146
eventTime: number,
146147
eventType: null|string,
148+
eventIsRepeat: boolean,
147149
renderStartTime: number,
148150
): void{
149151
if(supportsUserTiming){
@@ -158,7 +160,7 @@ export function logTransitionStart(
158160
: updateTime>0
159161
? updateTime
160162
: renderStartTime;
161-
performance.measure(eventType,reusableLaneOptions);
163+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
162164
}
163165
if(startTime>0){
164166
// Log the time from when we started an async transition until we called setState or started rendering.

‎packages/react-reconciler/src/ReactFiberRootScheduler.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
disableSchedulerTimeoutInWorkLoop,
1919
enableProfilerTimer,
2020
enableProfilerNestedUpdatePhase,
21+
enableComponentPerformanceTrack,
2122
enableSiblingPrerendering,
2223
}from'shared/ReactFeatureFlags';
2324
import{
@@ -64,6 +65,7 @@ import {
6465
supportsMicrotasks,
6566
scheduleMicrotask,
6667
shouldAttemptEagerTransition,
68+
trackSchedulerEvent,
6769
}from'./ReactFiberConfig';
6870

6971
importReactSharedInternalsfrom'shared/ReactSharedInternals';
@@ -225,6 +227,12 @@ function flushSyncWorkAcrossRoots_impl(
225227
}
226228

227229
functionprocessRootScheduleInMicrotask(){
230+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
231+
// Track the currently executing event if there is one so we can ignore this
232+
// event when logging events.
233+
trackSchedulerEvent();
234+
}
235+
228236
// This function is always called inside a microtask. It should never be
229237
// called synchronously.
230238
didScheduleMicrotask=false;
@@ -428,6 +436,12 @@ function performWorkOnRootViaSchedulerTask(
428436
resetNestedUpdateFlag();
429437
}
430438

439+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
440+
// Track the currently executing event if there is one so we can ignore this
441+
// event when logging events.
442+
trackSchedulerEvent();
443+
}
444+
431445
// Flush any pending passive effects before deciding which lanes to work on,
432446
// in case they schedule additional work.
433447
constoriginalCallbackNode=root.callbackNode;

‎packages/react-reconciler/src/ReactFiberWorkLoop.js‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
setCurrentUpdatePriority,
9191
getCurrentUpdatePriority,
9292
resolveUpdatePriority,
93+
trackSchedulerEvent,
9394
}from'./ReactFiberConfig';
9495

9596
import{createWorkInProgress,resetWorkInProgress}from'./ReactFiber';
@@ -229,13 +230,17 @@ import {
229230
}from'./ReactFiberConcurrentUpdates';
230231

231232
import{
233+
blockingClampTime,
232234
blockingUpdateTime,
233235
blockingEventTime,
234236
blockingEventType,
237+
blockingEventIsRepeat,
238+
transitionClampTime,
235239
transitionStartTime,
236240
transitionUpdateTime,
237241
transitionEventTime,
238242
transitionEventType,
243+
transitionEventIsRepeat,
239244
clearBlockingTimers,
240245
clearTransitionTimers,
241246
clampBlockingTimers,
@@ -938,6 +943,9 @@ export function performWorkOnRoot(
938943
}
939944
break;
940945
}elseif(exitStatus===RootDidNotComplete){
946+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
947+
finalizeRender(lanes,now());
948+
}
941949
// The render unwound without completing the tree. This happens in special
942950
// cases where need to exit the current render without producing a
943951
// consistent tree or committing.
@@ -1130,6 +1138,9 @@ function finishConcurrentRender(
11301138
// This is a transition, so we should exit without committing a
11311139
// placeholder and without scheduling a timeout. Delay indefinitely
11321140
// until we receive more data.
1141+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
1142+
finalizeRender(lanes,now());
1143+
}
11331144
constdidAttemptEntireTree=
11341145
!workInProgressRootDidSkipSuspendedSiblings;
11351146
markRootSuspended(
@@ -1655,19 +1666,31 @@ function prepareFreshStack(root: FiberRoot, lanes: Lanes): Fiber {
16551666

16561667
if(includesSyncLane(lanes)||includesBlockingLane(lanes)){
16571668
logBlockingStart(
1658-
blockingUpdateTime,
1659-
blockingEventTime,
1669+
blockingUpdateTime>=0&&blockingUpdateTime<blockingClampTime
1670+
? blockingClampTime
1671+
: blockingUpdateTime,
1672+
blockingEventTime>=0&&blockingEventTime<blockingClampTime
1673+
? blockingClampTime
1674+
: blockingEventTime,
16601675
blockingEventType,
1676+
blockingEventIsRepeat,
16611677
renderStartTime,
16621678
);
16631679
clearBlockingTimers();
16641680
}
16651681
if(includesTransitionLane(lanes)){
16661682
logTransitionStart(
1667-
transitionStartTime,
1668-
transitionUpdateTime,
1669-
transitionEventTime,
1683+
transitionStartTime>=0&&transitionStartTime<transitionClampTime
1684+
? transitionClampTime
1685+
: transitionStartTime,
1686+
transitionUpdateTime>=0&&transitionUpdateTime<transitionClampTime
1687+
? transitionClampTime
1688+
: transitionUpdateTime,
1689+
transitionEventTime>=0&&transitionEventTime<transitionClampTime
1690+
? transitionClampTime
1691+
: transitionEventTime,
16701692
transitionEventType,
1693+
transitionEventIsRepeat,
16711694
renderStartTime,
16721695
);
16731696
clearTransitionTimers();
@@ -3139,6 +3162,11 @@ function commitRootImpl(
31393162
// with setTimeout
31403163
pendingPassiveTransitions=transitions;
31413164
scheduleCallback(NormalSchedulerPriority,()=>{
3165+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
3166+
// Track the currently executing event if there is one so we can ignore this
3167+
// event when logging events.
3168+
trackSchedulerEvent();
3169+
}
31423170
flushPassiveEffects(true);
31433171
// This render triggered passive effects: release the root cache pool
31443172
// *after* passive effects fire to avoid freeing a cache pool that may

‎packages/react-reconciler/src/ReactProfilerTimer.js‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ export let componentEffectDuration: number = -0;
3636
exportletcomponentEffectStartTime: number=-1.1;
3737
exportletcomponentEffectEndTime: number=-1.1;
3838

39+
exportletblockingClampTime: number=-0;
3940
exportletblockingUpdateTime: number=-1.1;// First sync setState scheduled.
4041
exportletblockingEventTime: number=-1.1;// Event timeStamp of the first setState.
4142
export letblockingEventType: null|string=null;// Event type of the first setState.
43+
exportletblockingEventIsRepeat: boolean=false;
4244
// TODO: This should really be one per Transition lane.
45+
exportlettransitionClampTime: number=-0;
4346
exportlettransitionStartTime: number=-1.1;// First startTransition call before setState.
4447
exportlettransitionUpdateTime: number=-1.1;// First transition setState scheduled.
4548
exportlettransitionEventTime: number=-1.1;// Event timeStamp of the first transition.
4649
export lettransitionEventType: null|string=null;// Event type of the first transition.
50+
exportlettransitionEventIsRepeat: boolean=false;
4751

4852
exportfunctionstartUpdateTimerByLane(lane: Lane): void{
4953
if(!enableProfilerTimer||!enableComponentPerformanceTrack){
@@ -52,15 +56,25 @@ export function startUpdateTimerByLane(lane: Lane): void {
5256
if(isSyncLane(lane)||isBlockingLane(lane)){
5357
if(blockingUpdateTime<0){
5458
blockingUpdateTime=now();
55-
blockingEventTime=resolveEventTimeStamp();
56-
blockingEventType=resolveEventType();
59+
constnewEventTime=resolveEventTimeStamp();
60+
constnewEventType=resolveEventType();
61+
blockingEventIsRepeat=
62+
newEventTime===blockingEventTime&&
63+
newEventType===blockingEventType;
64+
blockingEventTime=newEventTime;
65+
blockingEventType=newEventType;
5766
}
5867
}elseif(isTransitionLane(lane)){
5968
if(transitionUpdateTime<0){
6069
transitionUpdateTime=now();
6170
if(transitionStartTime<0){
62-
transitionEventTime=resolveEventTimeStamp();
63-
transitionEventType=resolveEventType();
71+
constnewEventTime=resolveEventTimeStamp();
72+
constnewEventType=resolveEventType();
73+
transitionEventIsRepeat=
74+
newEventTime===transitionEventTime&&
75+
newEventType===transitionEventType;
76+
transitionEventTime=newEventTime;
77+
transitionEventType=newEventType;
6478
}
6579
}
6680
}
@@ -76,8 +90,13 @@ export function startAsyncTransitionTimer(): void {
7690
}
7791
if(transitionStartTime<0&&transitionUpdateTime<0){
7892
transitionStartTime=now();
79-
transitionEventTime=resolveEventTimeStamp();
80-
transitionEventType=resolveEventType();
93+
constnewEventTime=resolveEventTimeStamp();
94+
constnewEventType=resolveEventType();
95+
transitionEventIsRepeat=
96+
newEventTime===transitionEventTime&&
97+
newEventType===transitionEventType;
98+
transitionEventTime=newEventTime;
99+
transitionEventType=newEventType;
81100
}
82101
}
83102

@@ -115,12 +134,7 @@ export function clampBlockingTimers(finalTime: number): void {
115134
// If we had new updates come in while we were still rendering or committing, we don't want
116135
// those update times to create overlapping tracks in the performance timeline so we clamp
117136
// them to the end of the commit phase.
118-
if(blockingUpdateTime>=0&&blockingUpdateTime<finalTime){
119-
blockingUpdateTime=finalTime;
120-
}
121-
if(blockingEventTime>=0&&blockingEventTime<finalTime){
122-
blockingEventTime=finalTime;
123-
}
137+
blockingClampTime=finalTime;
124138
}
125139

126140
exportfunctionclampTransitionTimers(finalTime: number): void{
@@ -130,15 +144,7 @@ export function clampTransitionTimers(finalTime: number): void {
130144
// If we had new updates come in while we were still rendering or committing, we don't want
131145
// those update times to create overlapping tracks in the performance timeline so we clamp
132146
// them to the end of the commit phase.
133-
if(transitionStartTime>=0&&transitionStartTime<finalTime){
134-
transitionStartTime=finalTime;
135-
}
136-
if(transitionUpdateTime>=0&&transitionUpdateTime<finalTime){
137-
transitionUpdateTime=finalTime;
138-
}
139-
if(transitionEventTime>=0&&transitionEventTime<finalTime){
140-
transitionEventTime=finalTime;
141-
}
147+
transitionClampTime=finalTime;
142148
}
143149

144150
exportfunctionpushNestedEffectDurations(): number{

‎packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('ReactFiberHostContext', () => {
8383
}
8484
returnDefaultEventPriority;
8585
},
86+
trackSchedulerEvent: function(){},
8687
resolveEventType: function(){
8788
returnnull;
8889
},

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit c13986d

Browse files
authored
Fix Overlapping "message" Bug in Performance Track (#31528)
When you schedule a microtask from render or effect and then call setState (or ping) from there, the "event" is the event that React scheduled (which will be a postMessage). The event time of this new render will be before the last render finished. We usually clamp these but in this scenario the update doesn't happen while a render is happening. Causing overlapping events. Before: <img width="1229" alt="Screenshot 2024-11-12 at 11 01 30 PM" src="https://github.com/user-attachments/assets/9652cf3b-b358-453c-b295-1239cbb15952"> Therefore when we finalize a render we need to store the end of the last render so when we a new update comes in later with an event time earlier than that, we know to clamp it. There's also a special case here where when we enter the `RootDidNotComplete` or `RootSuspendedWithDelay` case we neither leave the root as in progress nor commit it. Those needs to finalize too. Really this should be modeled as a suspended track that we haven't added yet. That's the gap between "Blocked" and "message" below. After: <img width="1471" alt="Screenshot 2024-11-13 at 12 31 34 AM" src="https://github.com/user-attachments/assets/b24f994e-9055-4b10-ad29-ad9b36302ffc"> I also fixed an issue where we may log the same event name multiple times if we're rendering more than once in the same event. In this case I just leave a blank trace between the last commit and the next update. I also adding ignoring of the "message" event at all in these cases when the event is from React's scheduling itself.
1 parent 4686872 commit c13986d

12 files changed

Lines changed: 97 additions & 31 deletions

File tree

‎packages/react-art/src/ReactFiberConfigART.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ export function resolveUpdatePriority(): EventPriority {
363363
returncurrentUpdatePriority||DefaultEventPriority;
364364
}
365365

366+
exportfunctiontrackSchedulerEvent(): void{}
367+
366368
export functionresolveEventType(): null|string{
367369
returnnull;
368370
}

‎packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,19 @@ export function shouldAttemptEagerTransition(): boolean {
606606
returnfalse;
607607
}
608608

609+
letschedulerEvent: void|Event=undefined;
610+
exportfunctiontrackSchedulerEvent(): void{
611+
schedulerEvent=window.event;
612+
}
613+
609614
export functionresolveEventType(): null|string{
610615
constevent=window.event;
611-
returnevent ? event.type : null;
616+
returnevent&&event!==schedulerEvent? event.type : null;
612617
}
613618

614619
exportfunctionresolveEventTimeStamp(): number{
615620
constevent=window.event;
616-
returnevent ? event.timeStamp : -1.1;
621+
returnevent&&event!==schedulerEvent? event.timeStamp : -1.1;
617622
}
618623

619624
exportconstisPrimaryRenderer=true;

‎packages/react-native-renderer/src/ReactFiberConfigFabric.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ export function resolveUpdatePriority(): EventPriority {
372372
returnDefaultEventPriority;
373373
}
374374

375+
exportfunctiontrackSchedulerEvent(): void{}
376+
375377
export functionresolveEventType(): null|string{
376378
returnnull;
377379
}

‎packages/react-native-renderer/src/ReactFiberConfigNative.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ export function resolveUpdatePriority(): EventPriority {
288288
returnDefaultEventPriority;
289289
}
290290

291+
exportfunctiontrackSchedulerEvent(): void{}
292+
291293
export functionresolveEventType(): null|string{
292294
returnnull;
293295
}

‎packages/react-noop-renderer/src/createReactNoop.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
531531
returncurrentEventPriority;
532532
},
533533

534+
trackSchedulerEvent(): void{},
535+
534536
resolveEventType(): null|string{
535537
return null;
536538
},

‎packages/react-reconciler/src/ReactFiberPerformanceTrack.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export function logBlockingStart(
118118
updateTime: number,
119119
eventTime: number,
120120
eventType: null|string,
121+
eventIsRepeat: boolean,
121122
renderStartTime: number,
122123
): void{
123124
if(supportsUserTiming){
@@ -127,7 +128,7 @@ export function logBlockingStart(
127128
reusableLaneDevToolDetails.color='secondary-dark';
128129
reusableLaneOptions.start=eventTime;
129130
reusableLaneOptions.end=updateTime>0 ? updateTime : renderStartTime;
130-
performance.measure(eventType,reusableLaneOptions);
131+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
131132
}
132133
if(updateTime>0){
133134
// Log the time from when we called setState until we started rendering.
@@ -144,6 +145,7 @@ export function logTransitionStart(
144145
updateTime: number,
145146
eventTime: number,
146147
eventType: null|string,
148+
eventIsRepeat: boolean,
147149
renderStartTime: number,
148150
): void{
149151
if(supportsUserTiming){
@@ -158,7 +160,7 @@ export function logTransitionStart(
158160
: updateTime>0
159161
? updateTime
160162
: renderStartTime;
161-
performance.measure(eventType,reusableLaneOptions);
163+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
162164
}
163165
if(startTime>0){
164166
// Log the time from when we started an async transition until we called setState or started rendering.

‎packages/react-reconciler/src/ReactFiberRootScheduler.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
disableSchedulerTimeoutInWorkLoop,
1919
enableProfilerTimer,
2020
enableProfilerNestedUpdatePhase,
21+
enableComponentPerformanceTrack,
2122
enableSiblingPrerendering,
2223
}from'shared/ReactFeatureFlags';
2324
import{
@@ -64,6 +65,7 @@ import {
6465
supportsMicrotasks,
6566
scheduleMicrotask,
6667
shouldAttemptEagerTransition,
68+
trackSchedulerEvent,
6769
}from'./ReactFiberConfig';
6870

6971
importReactSharedInternalsfrom'shared/ReactSharedInternals';
@@ -225,6 +227,12 @@ function flushSyncWorkAcrossRoots_impl(
225227
}
226228

227229
functionprocessRootScheduleInMicrotask(){
230+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
231+
// Track the currently executing event if there is one so we can ignore this
232+
// event when logging events.
233+
trackSchedulerEvent();
234+
}
235+
228236
// This function is always called inside a microtask. It should never be
229237
// called synchronously.
230238
didScheduleMicrotask=false;
@@ -428,6 +436,12 @@ function performWorkOnRootViaSchedulerTask(
428436
resetNestedUpdateFlag();
429437
}
430438

439+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
440+
// Track the currently executing event if there is one so we can ignore this
441+
// event when logging events.
442+
trackSchedulerEvent();
443+
}
444+
431445
// Flush any pending passive effects before deciding which lanes to work on,
432446
// in case they schedule additional work.
433447
constoriginalCallbackNode=root.callbackNode;

‎packages/react-reconciler/src/ReactFiberWorkLoop.js‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
setCurrentUpdatePriority,
9191
getCurrentUpdatePriority,
9292
resolveUpdatePriority,
93+
trackSchedulerEvent,
9394
}from'./ReactFiberConfig';
9495

9596
import{createWorkInProgress,resetWorkInProgress}from'./ReactFiber';
@@ -229,13 +230,17 @@ import {
229230
}from'./ReactFiberConcurrentUpdates';
230231

231232
import{
233+
blockingClampTime,
232234
blockingUpdateTime,
233235
blockingEventTime,
234236
blockingEventType,
237+
blockingEventIsRepeat,
238+
transitionClampTime,
235239
transitionStartTime,
236240
transitionUpdateTime,
237241
transitionEventTime,
238242
transitionEventType,
243+
transitionEventIsRepeat,
239244
clearBlockingTimers,
240245
clearTransitionTimers,
241246
clampBlockingTimers,
@@ -938,6 +943,9 @@ export function performWorkOnRoot(
938943
}
939944
break;
940945
}elseif(exitStatus===RootDidNotComplete){
946+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
947+
finalizeRender(lanes,now());
948+
}
941949
// The render unwound without completing the tree. This happens in special
942950
// cases where need to exit the current render without producing a
943951
// consistent tree or committing.
@@ -1130,6 +1138,9 @@ function finishConcurrentRender(
11301138
// This is a transition, so we should exit without committing a
11311139
// placeholder and without scheduling a timeout. Delay indefinitely
11321140
// until we receive more data.
1141+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
1142+
finalizeRender(lanes,now());
1143+
}
11331144
constdidAttemptEntireTree=
11341145
!workInProgressRootDidSkipSuspendedSiblings;
11351146
markRootSuspended(
@@ -1655,19 +1666,31 @@ function prepareFreshStack(root: FiberRoot, lanes: Lanes): Fiber {
16551666

16561667
if(includesSyncLane(lanes)||includesBlockingLane(lanes)){
16571668
logBlockingStart(
1658-
blockingUpdateTime,
1659-
blockingEventTime,
1669+
blockingUpdateTime>=0&&blockingUpdateTime<blockingClampTime
1670+
? blockingClampTime
1671+
: blockingUpdateTime,
1672+
blockingEventTime>=0&&blockingEventTime<blockingClampTime
1673+
? blockingClampTime
1674+
: blockingEventTime,
16601675
blockingEventType,
1676+
blockingEventIsRepeat,
16611677
renderStartTime,
16621678
);
16631679
clearBlockingTimers();
16641680
}
16651681
if(includesTransitionLane(lanes)){
16661682
logTransitionStart(
1667-
transitionStartTime,
1668-
transitionUpdateTime,
1669-
transitionEventTime,
1683+
transitionStartTime>=0&&transitionStartTime<transitionClampTime
1684+
? transitionClampTime
1685+
: transitionStartTime,
1686+
transitionUpdateTime>=0&&transitionUpdateTime<transitionClampTime
1687+
? transitionClampTime
1688+
: transitionUpdateTime,
1689+
transitionEventTime>=0&&transitionEventTime<transitionClampTime
1690+
? transitionClampTime
1691+
: transitionEventTime,
16701692
transitionEventType,
1693+
transitionEventIsRepeat,
16711694
renderStartTime,
16721695
);
16731696
clearTransitionTimers();
@@ -3139,6 +3162,11 @@ function commitRootImpl(
31393162
// with setTimeout
31403163
pendingPassiveTransitions=transitions;
31413164
scheduleCallback(NormalSchedulerPriority,()=>{
3165+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
3166+
// Track the currently executing event if there is one so we can ignore this
3167+
// event when logging events.
3168+
trackSchedulerEvent();
3169+
}
31423170
flushPassiveEffects(true);
31433171
// This render triggered passive effects: release the root cache pool
31443172
// *after* passive effects fire to avoid freeing a cache pool that may

‎packages/react-reconciler/src/ReactProfilerTimer.js‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ export let componentEffectDuration: number = -0;
3636
exportletcomponentEffectStartTime: number=-1.1;
3737
exportletcomponentEffectEndTime: number=-1.1;
3838

39+
exportletblockingClampTime: number=-0;
3940
exportletblockingUpdateTime: number=-1.1;// First sync setState scheduled.
4041
exportletblockingEventTime: number=-1.1;// Event timeStamp of the first setState.
4142
export letblockingEventType: null|string=null;// Event type of the first setState.
43+
exportletblockingEventIsRepeat: boolean=false;
4244
// TODO: This should really be one per Transition lane.
45+
exportlettransitionClampTime: number=-0;
4346
exportlettransitionStartTime: number=-1.1;// First startTransition call before setState.
4447
exportlettransitionUpdateTime: number=-1.1;// First transition setState scheduled.
4548
exportlettransitionEventTime: number=-1.1;// Event timeStamp of the first transition.
4649
export lettransitionEventType: null|string=null;// Event type of the first transition.
50+
exportlettransitionEventIsRepeat: boolean=false;
4751

4852
exportfunctionstartUpdateTimerByLane(lane: Lane): void{
4953
if(!enableProfilerTimer||!enableComponentPerformanceTrack){
@@ -52,15 +56,25 @@ export function startUpdateTimerByLane(lane: Lane): void {
5256
if(isSyncLane(lane)||isBlockingLane(lane)){
5357
if(blockingUpdateTime<0){
5458
blockingUpdateTime=now();
55-
blockingEventTime=resolveEventTimeStamp();
56-
blockingEventType=resolveEventType();
59+
constnewEventTime=resolveEventTimeStamp();
60+
constnewEventType=resolveEventType();
61+
blockingEventIsRepeat=
62+
newEventTime===blockingEventTime&&
63+
newEventType===blockingEventType;
64+
blockingEventTime=newEventTime;
65+
blockingEventType=newEventType;
5766
}
5867
}elseif(isTransitionLane(lane)){
5968
if(transitionUpdateTime<0){
6069
transitionUpdateTime=now();
6170
if(transitionStartTime<0){
62-
transitionEventTime=resolveEventTimeStamp();
63-
transitionEventType=resolveEventType();
71+
constnewEventTime=resolveEventTimeStamp();
72+
constnewEventType=resolveEventType();
73+
transitionEventIsRepeat=
74+
newEventTime===transitionEventTime&&
75+
newEventType===transitionEventType;
76+
transitionEventTime=newEventTime;
77+
transitionEventType=newEventType;
6478
}
6579
}
6680
}
@@ -76,8 +90,13 @@ export function startAsyncTransitionTimer(): void {
7690
}
7791
if(transitionStartTime<0&&transitionUpdateTime<0){
7892
transitionStartTime=now();
79-
transitionEventTime=resolveEventTimeStamp();
80-
transitionEventType=resolveEventType();
93+
constnewEventTime=resolveEventTimeStamp();
94+
constnewEventType=resolveEventType();
95+
transitionEventIsRepeat=
96+
newEventTime===transitionEventTime&&
97+
newEventType===transitionEventType;
98+
transitionEventTime=newEventTime;
99+
transitionEventType=newEventType;
81100
}
82101
}
83102

@@ -115,12 +134,7 @@ export function clampBlockingTimers(finalTime: number): void {
115134
// If we had new updates come in while we were still rendering or committing, we don't want
116135
// those update times to create overlapping tracks in the performance timeline so we clamp
117136
// them to the end of the commit phase.
118-
if(blockingUpdateTime>=0&&blockingUpdateTime<finalTime){
119-
blockingUpdateTime=finalTime;
120-
}
121-
if(blockingEventTime>=0&&blockingEventTime<finalTime){
122-
blockingEventTime=finalTime;
123-
}
137+
blockingClampTime=finalTime;
124138
}
125139

126140
exportfunctionclampTransitionTimers(finalTime: number): void{
@@ -130,15 +144,7 @@ export function clampTransitionTimers(finalTime: number): void {
130144
// If we had new updates come in while we were still rendering or committing, we don't want
131145
// those update times to create overlapping tracks in the performance timeline so we clamp
132146
// them to the end of the commit phase.
133-
if(transitionStartTime>=0&&transitionStartTime<finalTime){
134-
transitionStartTime=finalTime;
135-
}
136-
if(transitionUpdateTime>=0&&transitionUpdateTime<finalTime){
137-
transitionUpdateTime=finalTime;
138-
}
139-
if(transitionEventTime>=0&&transitionEventTime<finalTime){
140-
transitionEventTime=finalTime;
141-
}
147+
transitionClampTime=finalTime;
142148
}
143149

144150
exportfunctionpushNestedEffectDurations(): number{

‎packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('ReactFiberHostContext', () => {
8383
}
8484
returnDefaultEventPriority;
8585
},
86+
trackSchedulerEvent: function(){},
8687
resolveEventType: function(){
8788
returnnull;
8889
},

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit c13986d

Browse files
authored
Fix Overlapping "message" Bug in Performance Track (#31528)
When you schedule a microtask from render or effect and then call setState (or ping) from there, the "event" is the event that React scheduled (which will be a postMessage). The event time of this new render will be before the last render finished. We usually clamp these but in this scenario the update doesn't happen while a render is happening. Causing overlapping events. Before: <img width="1229" alt="Screenshot 2024-11-12 at 11 01 30 PM" src="https://github.com/user-attachments/assets/9652cf3b-b358-453c-b295-1239cbb15952"> Therefore when we finalize a render we need to store the end of the last render so when we a new update comes in later with an event time earlier than that, we know to clamp it. There's also a special case here where when we enter the `RootDidNotComplete` or `RootSuspendedWithDelay` case we neither leave the root as in progress nor commit it. Those needs to finalize too. Really this should be modeled as a suspended track that we haven't added yet. That's the gap between "Blocked" and "message" below. After: <img width="1471" alt="Screenshot 2024-11-13 at 12 31 34 AM" src="https://github.com/user-attachments/assets/b24f994e-9055-4b10-ad29-ad9b36302ffc"> I also fixed an issue where we may log the same event name multiple times if we're rendering more than once in the same event. In this case I just leave a blank trace between the last commit and the next update. I also adding ignoring of the "message" event at all in these cases when the event is from React's scheduling itself.
1 parent 4686872 commit c13986d

12 files changed

Lines changed: 97 additions & 31 deletions

File tree

‎packages/react-art/src/ReactFiberConfigART.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ export function resolveUpdatePriority(): EventPriority {
363363
returncurrentUpdatePriority||DefaultEventPriority;
364364
}
365365

366+
exportfunctiontrackSchedulerEvent(): void{}
367+
366368
export functionresolveEventType(): null|string{
367369
returnnull;
368370
}

‎packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,19 @@ export function shouldAttemptEagerTransition(): boolean {
606606
returnfalse;
607607
}
608608

609+
letschedulerEvent: void|Event=undefined;
610+
exportfunctiontrackSchedulerEvent(): void{
611+
schedulerEvent=window.event;
612+
}
613+
609614
export functionresolveEventType(): null|string{
610615
constevent=window.event;
611-
returnevent ? event.type : null;
616+
returnevent&&event!==schedulerEvent? event.type : null;
612617
}
613618

614619
exportfunctionresolveEventTimeStamp(): number{
615620
constevent=window.event;
616-
returnevent ? event.timeStamp : -1.1;
621+
returnevent&&event!==schedulerEvent? event.timeStamp : -1.1;
617622
}
618623

619624
exportconstisPrimaryRenderer=true;

‎packages/react-native-renderer/src/ReactFiberConfigFabric.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ export function resolveUpdatePriority(): EventPriority {
372372
returnDefaultEventPriority;
373373
}
374374

375+
exportfunctiontrackSchedulerEvent(): void{}
376+
375377
export functionresolveEventType(): null|string{
376378
returnnull;
377379
}

‎packages/react-native-renderer/src/ReactFiberConfigNative.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ export function resolveUpdatePriority(): EventPriority {
288288
returnDefaultEventPriority;
289289
}
290290

291+
exportfunctiontrackSchedulerEvent(): void{}
292+
291293
export functionresolveEventType(): null|string{
292294
returnnull;
293295
}

‎packages/react-noop-renderer/src/createReactNoop.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
531531
returncurrentEventPriority;
532532
},
533533

534+
trackSchedulerEvent(): void{},
535+
534536
resolveEventType(): null|string{
535537
return null;
536538
},

‎packages/react-reconciler/src/ReactFiberPerformanceTrack.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export function logBlockingStart(
118118
updateTime: number,
119119
eventTime: number,
120120
eventType: null|string,
121+
eventIsRepeat: boolean,
121122
renderStartTime: number,
122123
): void{
123124
if(supportsUserTiming){
@@ -127,7 +128,7 @@ export function logBlockingStart(
127128
reusableLaneDevToolDetails.color='secondary-dark';
128129
reusableLaneOptions.start=eventTime;
129130
reusableLaneOptions.end=updateTime>0 ? updateTime : renderStartTime;
130-
performance.measure(eventType,reusableLaneOptions);
131+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
131132
}
132133
if(updateTime>0){
133134
// Log the time from when we called setState until we started rendering.
@@ -144,6 +145,7 @@ export function logTransitionStart(
144145
updateTime: number,
145146
eventTime: number,
146147
eventType: null|string,
148+
eventIsRepeat: boolean,
147149
renderStartTime: number,
148150
): void{
149151
if(supportsUserTiming){
@@ -158,7 +160,7 @@ export function logTransitionStart(
158160
: updateTime>0
159161
? updateTime
160162
: renderStartTime;
161-
performance.measure(eventType,reusableLaneOptions);
163+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
162164
}
163165
if(startTime>0){
164166
// Log the time from when we started an async transition until we called setState or started rendering.

‎packages/react-reconciler/src/ReactFiberRootScheduler.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
disableSchedulerTimeoutInWorkLoop,
1919
enableProfilerTimer,
2020
enableProfilerNestedUpdatePhase,
21+
enableComponentPerformanceTrack,
2122
enableSiblingPrerendering,
2223
}from'shared/ReactFeatureFlags';
2324
import{
@@ -64,6 +65,7 @@ import {
6465
supportsMicrotasks,
6566
scheduleMicrotask,
6667
shouldAttemptEagerTransition,
68+
trackSchedulerEvent,
6769
}from'./ReactFiberConfig';
6870

6971
importReactSharedInternalsfrom'shared/ReactSharedInternals';
@@ -225,6 +227,12 @@ function flushSyncWorkAcrossRoots_impl(
225227
}
226228

227229
functionprocessRootScheduleInMicrotask(){
230+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
231+
// Track the currently executing event if there is one so we can ignore this
232+
// event when logging events.
233+
trackSchedulerEvent();
234+
}
235+
228236
// This function is always called inside a microtask. It should never be
229237
// called synchronously.
230238
didScheduleMicrotask=false;
@@ -428,6 +436,12 @@ function performWorkOnRootViaSchedulerTask(
428436
resetNestedUpdateFlag();
429437
}
430438

439+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
440+
// Track the currently executing event if there is one so we can ignore this
441+
// event when logging events.
442+
trackSchedulerEvent();
443+
}
444+
431445
// Flush any pending passive effects before deciding which lanes to work on,
432446
// in case they schedule additional work.
433447
constoriginalCallbackNode=root.callbackNode;

‎packages/react-reconciler/src/ReactFiberWorkLoop.js‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
setCurrentUpdatePriority,
9191
getCurrentUpdatePriority,
9292
resolveUpdatePriority,
93+
trackSchedulerEvent,
9394
}from'./ReactFiberConfig';
9495

9596
import{createWorkInProgress,resetWorkInProgress}from'./ReactFiber';
@@ -229,13 +230,17 @@ import {
229230
}from'./ReactFiberConcurrentUpdates';
230231

231232
import{
233+
blockingClampTime,
232234
blockingUpdateTime,
233235
blockingEventTime,
234236
blockingEventType,
237+
blockingEventIsRepeat,
238+
transitionClampTime,
235239
transitionStartTime,
236240
transitionUpdateTime,
237241
transitionEventTime,
238242
transitionEventType,
243+
transitionEventIsRepeat,
239244
clearBlockingTimers,
240245
clearTransitionTimers,
241246
clampBlockingTimers,
@@ -938,6 +943,9 @@ export function performWorkOnRoot(
938943
}
939944
break;
940945
}elseif(exitStatus===RootDidNotComplete){
946+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
947+
finalizeRender(lanes,now());
948+
}
941949
// The render unwound without completing the tree. This happens in special
942950
// cases where need to exit the current render without producing a
943951
// consistent tree or committing.
@@ -1130,6 +1138,9 @@ function finishConcurrentRender(
11301138
// This is a transition, so we should exit without committing a
11311139
// placeholder and without scheduling a timeout. Delay indefinitely
11321140
// until we receive more data.
1141+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
1142+
finalizeRender(lanes,now());
1143+
}
11331144
constdidAttemptEntireTree=
11341145
!workInProgressRootDidSkipSuspendedSiblings;
11351146
markRootSuspended(
@@ -1655,19 +1666,31 @@ function prepareFreshStack(root: FiberRoot, lanes: Lanes): Fiber {
16551666

16561667
if(includesSyncLane(lanes)||includesBlockingLane(lanes)){
16571668
logBlockingStart(
1658-
blockingUpdateTime,
1659-
blockingEventTime,
1669+
blockingUpdateTime>=0&&blockingUpdateTime<blockingClampTime
1670+
? blockingClampTime
1671+
: blockingUpdateTime,
1672+
blockingEventTime>=0&&blockingEventTime<blockingClampTime
1673+
? blockingClampTime
1674+
: blockingEventTime,
16601675
blockingEventType,
1676+
blockingEventIsRepeat,
16611677
renderStartTime,
16621678
);
16631679
clearBlockingTimers();
16641680
}
16651681
if(includesTransitionLane(lanes)){
16661682
logTransitionStart(
1667-
transitionStartTime,
1668-
transitionUpdateTime,
1669-
transitionEventTime,
1683+
transitionStartTime>=0&&transitionStartTime<transitionClampTime
1684+
? transitionClampTime
1685+
: transitionStartTime,
1686+
transitionUpdateTime>=0&&transitionUpdateTime<transitionClampTime
1687+
? transitionClampTime
1688+
: transitionUpdateTime,
1689+
transitionEventTime>=0&&transitionEventTime<transitionClampTime
1690+
? transitionClampTime
1691+
: transitionEventTime,
16701692
transitionEventType,
1693+
transitionEventIsRepeat,
16711694
renderStartTime,
16721695
);
16731696
clearTransitionTimers();
@@ -3139,6 +3162,11 @@ function commitRootImpl(
31393162
// with setTimeout
31403163
pendingPassiveTransitions=transitions;
31413164
scheduleCallback(NormalSchedulerPriority,()=>{
3165+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
3166+
// Track the currently executing event if there is one so we can ignore this
3167+
// event when logging events.
3168+
trackSchedulerEvent();
3169+
}
31423170
flushPassiveEffects(true);
31433171
// This render triggered passive effects: release the root cache pool
31443172
// *after* passive effects fire to avoid freeing a cache pool that may

‎packages/react-reconciler/src/ReactProfilerTimer.js‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ export let componentEffectDuration: number = -0;
3636
exportletcomponentEffectStartTime: number=-1.1;
3737
exportletcomponentEffectEndTime: number=-1.1;
3838

39+
exportletblockingClampTime: number=-0;
3940
exportletblockingUpdateTime: number=-1.1;// First sync setState scheduled.
4041
exportletblockingEventTime: number=-1.1;// Event timeStamp of the first setState.
4142
export letblockingEventType: null|string=null;// Event type of the first setState.
43+
exportletblockingEventIsRepeat: boolean=false;
4244
// TODO: This should really be one per Transition lane.
45+
exportlettransitionClampTime: number=-0;
4346
exportlettransitionStartTime: number=-1.1;// First startTransition call before setState.
4447
exportlettransitionUpdateTime: number=-1.1;// First transition setState scheduled.
4548
exportlettransitionEventTime: number=-1.1;// Event timeStamp of the first transition.
4649
export lettransitionEventType: null|string=null;// Event type of the first transition.
50+
exportlettransitionEventIsRepeat: boolean=false;
4751

4852
exportfunctionstartUpdateTimerByLane(lane: Lane): void{
4953
if(!enableProfilerTimer||!enableComponentPerformanceTrack){
@@ -52,15 +56,25 @@ export function startUpdateTimerByLane(lane: Lane): void {
5256
if(isSyncLane(lane)||isBlockingLane(lane)){
5357
if(blockingUpdateTime<0){
5458
blockingUpdateTime=now();
55-
blockingEventTime=resolveEventTimeStamp();
56-
blockingEventType=resolveEventType();
59+
constnewEventTime=resolveEventTimeStamp();
60+
constnewEventType=resolveEventType();
61+
blockingEventIsRepeat=
62+
newEventTime===blockingEventTime&&
63+
newEventType===blockingEventType;
64+
blockingEventTime=newEventTime;
65+
blockingEventType=newEventType;
5766
}
5867
}elseif(isTransitionLane(lane)){
5968
if(transitionUpdateTime<0){
6069
transitionUpdateTime=now();
6170
if(transitionStartTime<0){
62-
transitionEventTime=resolveEventTimeStamp();
63-
transitionEventType=resolveEventType();
71+
constnewEventTime=resolveEventTimeStamp();
72+
constnewEventType=resolveEventType();
73+
transitionEventIsRepeat=
74+
newEventTime===transitionEventTime&&
75+
newEventType===transitionEventType;
76+
transitionEventTime=newEventTime;
77+
transitionEventType=newEventType;
6478
}
6579
}
6680
}
@@ -76,8 +90,13 @@ export function startAsyncTransitionTimer(): void {
7690
}
7791
if(transitionStartTime<0&&transitionUpdateTime<0){
7892
transitionStartTime=now();
79-
transitionEventTime=resolveEventTimeStamp();
80-
transitionEventType=resolveEventType();
93+
constnewEventTime=resolveEventTimeStamp();
94+
constnewEventType=resolveEventType();
95+
transitionEventIsRepeat=
96+
newEventTime===transitionEventTime&&
97+
newEventType===transitionEventType;
98+
transitionEventTime=newEventTime;
99+
transitionEventType=newEventType;
81100
}
82101
}
83102

@@ -115,12 +134,7 @@ export function clampBlockingTimers(finalTime: number): void {
115134
// If we had new updates come in while we were still rendering or committing, we don't want
116135
// those update times to create overlapping tracks in the performance timeline so we clamp
117136
// them to the end of the commit phase.
118-
if(blockingUpdateTime>=0&&blockingUpdateTime<finalTime){
119-
blockingUpdateTime=finalTime;
120-
}
121-
if(blockingEventTime>=0&&blockingEventTime<finalTime){
122-
blockingEventTime=finalTime;
123-
}
137+
blockingClampTime=finalTime;
124138
}
125139

126140
exportfunctionclampTransitionTimers(finalTime: number): void{
@@ -130,15 +144,7 @@ export function clampTransitionTimers(finalTime: number): void {
130144
// If we had new updates come in while we were still rendering or committing, we don't want
131145
// those update times to create overlapping tracks in the performance timeline so we clamp
132146
// them to the end of the commit phase.
133-
if(transitionStartTime>=0&&transitionStartTime<finalTime){
134-
transitionStartTime=finalTime;
135-
}
136-
if(transitionUpdateTime>=0&&transitionUpdateTime<finalTime){
137-
transitionUpdateTime=finalTime;
138-
}
139-
if(transitionEventTime>=0&&transitionEventTime<finalTime){
140-
transitionEventTime=finalTime;
141-
}
147+
transitionClampTime=finalTime;
142148
}
143149

144150
exportfunctionpushNestedEffectDurations(): number{

‎packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('ReactFiberHostContext', () => {
8383
}
8484
returnDefaultEventPriority;
8585
},
86+
trackSchedulerEvent: function(){},
8687
resolveEventType: function(){
8788
returnnull;
8889
},

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit c13986d

Browse files
authored
Fix Overlapping "message" Bug in Performance Track (#31528)
When you schedule a microtask from render or effect and then call setState (or ping) from there, the "event" is the event that React scheduled (which will be a postMessage). The event time of this new render will be before the last render finished. We usually clamp these but in this scenario the update doesn't happen while a render is happening. Causing overlapping events. Before: <img width="1229" alt="Screenshot 2024-11-12 at 11 01 30 PM" src="https://github.com/user-attachments/assets/9652cf3b-b358-453c-b295-1239cbb15952"> Therefore when we finalize a render we need to store the end of the last render so when we a new update comes in later with an event time earlier than that, we know to clamp it. There's also a special case here where when we enter the `RootDidNotComplete` or `RootSuspendedWithDelay` case we neither leave the root as in progress nor commit it. Those needs to finalize too. Really this should be modeled as a suspended track that we haven't added yet. That's the gap between "Blocked" and "message" below. After: <img width="1471" alt="Screenshot 2024-11-13 at 12 31 34 AM" src="https://github.com/user-attachments/assets/b24f994e-9055-4b10-ad29-ad9b36302ffc"> I also fixed an issue where we may log the same event name multiple times if we're rendering more than once in the same event. In this case I just leave a blank trace between the last commit and the next update. I also adding ignoring of the "message" event at all in these cases when the event is from React's scheduling itself.
1 parent 4686872 commit c13986d

12 files changed

Lines changed: 97 additions & 31 deletions

File tree

‎packages/react-art/src/ReactFiberConfigART.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ export function resolveUpdatePriority(): EventPriority {
363363
returncurrentUpdatePriority||DefaultEventPriority;
364364
}
365365

366+
exportfunctiontrackSchedulerEvent(): void{}
367+
366368
export functionresolveEventType(): null|string{
367369
returnnull;
368370
}

‎packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,19 @@ export function shouldAttemptEagerTransition(): boolean {
606606
returnfalse;
607607
}
608608

609+
letschedulerEvent: void|Event=undefined;
610+
exportfunctiontrackSchedulerEvent(): void{
611+
schedulerEvent=window.event;
612+
}
613+
609614
export functionresolveEventType(): null|string{
610615
constevent=window.event;
611-
returnevent ? event.type : null;
616+
returnevent&&event!==schedulerEvent? event.type : null;
612617
}
613618

614619
exportfunctionresolveEventTimeStamp(): number{
615620
constevent=window.event;
616-
returnevent ? event.timeStamp : -1.1;
621+
returnevent&&event!==schedulerEvent? event.timeStamp : -1.1;
617622
}
618623

619624
exportconstisPrimaryRenderer=true;

‎packages/react-native-renderer/src/ReactFiberConfigFabric.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ export function resolveUpdatePriority(): EventPriority {
372372
returnDefaultEventPriority;
373373
}
374374

375+
exportfunctiontrackSchedulerEvent(): void{}
376+
375377
export functionresolveEventType(): null|string{
376378
returnnull;
377379
}

‎packages/react-native-renderer/src/ReactFiberConfigNative.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ export function resolveUpdatePriority(): EventPriority {
288288
returnDefaultEventPriority;
289289
}
290290

291+
exportfunctiontrackSchedulerEvent(): void{}
292+
291293
export functionresolveEventType(): null|string{
292294
returnnull;
293295
}

‎packages/react-noop-renderer/src/createReactNoop.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
531531
returncurrentEventPriority;
532532
},
533533

534+
trackSchedulerEvent(): void{},
535+
534536
resolveEventType(): null|string{
535537
return null;
536538
},

‎packages/react-reconciler/src/ReactFiberPerformanceTrack.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export function logBlockingStart(
118118
updateTime: number,
119119
eventTime: number,
120120
eventType: null|string,
121+
eventIsRepeat: boolean,
121122
renderStartTime: number,
122123
): void{
123124
if(supportsUserTiming){
@@ -127,7 +128,7 @@ export function logBlockingStart(
127128
reusableLaneDevToolDetails.color='secondary-dark';
128129
reusableLaneOptions.start=eventTime;
129130
reusableLaneOptions.end=updateTime>0 ? updateTime : renderStartTime;
130-
performance.measure(eventType,reusableLaneOptions);
131+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
131132
}
132133
if(updateTime>0){
133134
// Log the time from when we called setState until we started rendering.
@@ -144,6 +145,7 @@ export function logTransitionStart(
144145
updateTime: number,
145146
eventTime: number,
146147
eventType: null|string,
148+
eventIsRepeat: boolean,
147149
renderStartTime: number,
148150
): void{
149151
if(supportsUserTiming){
@@ -158,7 +160,7 @@ export function logTransitionStart(
158160
: updateTime>0
159161
? updateTime
160162
: renderStartTime;
161-
performance.measure(eventType,reusableLaneOptions);
163+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
162164
}
163165
if(startTime>0){
164166
// Log the time from when we started an async transition until we called setState or started rendering.

‎packages/react-reconciler/src/ReactFiberRootScheduler.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
disableSchedulerTimeoutInWorkLoop,
1919
enableProfilerTimer,
2020
enableProfilerNestedUpdatePhase,
21+
enableComponentPerformanceTrack,
2122
enableSiblingPrerendering,
2223
}from'shared/ReactFeatureFlags';
2324
import{
@@ -64,6 +65,7 @@ import {
6465
supportsMicrotasks,
6566
scheduleMicrotask,
6667
shouldAttemptEagerTransition,
68+
trackSchedulerEvent,
6769
}from'./ReactFiberConfig';
6870

6971
importReactSharedInternalsfrom'shared/ReactSharedInternals';
@@ -225,6 +227,12 @@ function flushSyncWorkAcrossRoots_impl(
225227
}
226228

227229
functionprocessRootScheduleInMicrotask(){
230+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
231+
// Track the currently executing event if there is one so we can ignore this
232+
// event when logging events.
233+
trackSchedulerEvent();
234+
}
235+
228236
// This function is always called inside a microtask. It should never be
229237
// called synchronously.
230238
didScheduleMicrotask=false;
@@ -428,6 +436,12 @@ function performWorkOnRootViaSchedulerTask(
428436
resetNestedUpdateFlag();
429437
}
430438

439+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
440+
// Track the currently executing event if there is one so we can ignore this
441+
// event when logging events.
442+
trackSchedulerEvent();
443+
}
444+
431445
// Flush any pending passive effects before deciding which lanes to work on,
432446
// in case they schedule additional work.
433447
constoriginalCallbackNode=root.callbackNode;

‎packages/react-reconciler/src/ReactFiberWorkLoop.js‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
setCurrentUpdatePriority,
9191
getCurrentUpdatePriority,
9292
resolveUpdatePriority,
93+
trackSchedulerEvent,
9394
}from'./ReactFiberConfig';
9495

9596
import{createWorkInProgress,resetWorkInProgress}from'./ReactFiber';
@@ -229,13 +230,17 @@ import {
229230
}from'./ReactFiberConcurrentUpdates';
230231

231232
import{
233+
blockingClampTime,
232234
blockingUpdateTime,
233235
blockingEventTime,
234236
blockingEventType,
237+
blockingEventIsRepeat,
238+
transitionClampTime,
235239
transitionStartTime,
236240
transitionUpdateTime,
237241
transitionEventTime,
238242
transitionEventType,
243+
transitionEventIsRepeat,
239244
clearBlockingTimers,
240245
clearTransitionTimers,
241246
clampBlockingTimers,
@@ -938,6 +943,9 @@ export function performWorkOnRoot(
938943
}
939944
break;
940945
}elseif(exitStatus===RootDidNotComplete){
946+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
947+
finalizeRender(lanes,now());
948+
}
941949
// The render unwound without completing the tree. This happens in special
942950
// cases where need to exit the current render without producing a
943951
// consistent tree or committing.
@@ -1130,6 +1138,9 @@ function finishConcurrentRender(
11301138
// This is a transition, so we should exit without committing a
11311139
// placeholder and without scheduling a timeout. Delay indefinitely
11321140
// until we receive more data.
1141+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
1142+
finalizeRender(lanes,now());
1143+
}
11331144
constdidAttemptEntireTree=
11341145
!workInProgressRootDidSkipSuspendedSiblings;
11351146
markRootSuspended(
@@ -1655,19 +1666,31 @@ function prepareFreshStack(root: FiberRoot, lanes: Lanes): Fiber {
16551666

16561667
if(includesSyncLane(lanes)||includesBlockingLane(lanes)){
16571668
logBlockingStart(
1658-
blockingUpdateTime,
1659-
blockingEventTime,
1669+
blockingUpdateTime>=0&&blockingUpdateTime<blockingClampTime
1670+
? blockingClampTime
1671+
: blockingUpdateTime,
1672+
blockingEventTime>=0&&blockingEventTime<blockingClampTime
1673+
? blockingClampTime
1674+
: blockingEventTime,
16601675
blockingEventType,
1676+
blockingEventIsRepeat,
16611677
renderStartTime,
16621678
);
16631679
clearBlockingTimers();
16641680
}
16651681
if(includesTransitionLane(lanes)){
16661682
logTransitionStart(
1667-
transitionStartTime,
1668-
transitionUpdateTime,
1669-
transitionEventTime,
1683+
transitionStartTime>=0&&transitionStartTime<transitionClampTime
1684+
? transitionClampTime
1685+
: transitionStartTime,
1686+
transitionUpdateTime>=0&&transitionUpdateTime<transitionClampTime
1687+
? transitionClampTime
1688+
: transitionUpdateTime,
1689+
transitionEventTime>=0&&transitionEventTime<transitionClampTime
1690+
? transitionClampTime
1691+
: transitionEventTime,
16701692
transitionEventType,
1693+
transitionEventIsRepeat,
16711694
renderStartTime,
16721695
);
16731696
clearTransitionTimers();
@@ -3139,6 +3162,11 @@ function commitRootImpl(
31393162
// with setTimeout
31403163
pendingPassiveTransitions=transitions;
31413164
scheduleCallback(NormalSchedulerPriority,()=>{
3165+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
3166+
// Track the currently executing event if there is one so we can ignore this
3167+
// event when logging events.
3168+
trackSchedulerEvent();
3169+
}
31423170
flushPassiveEffects(true);
31433171
// This render triggered passive effects: release the root cache pool
31443172
// *after* passive effects fire to avoid freeing a cache pool that may

‎packages/react-reconciler/src/ReactProfilerTimer.js‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ export let componentEffectDuration: number = -0;
3636
exportletcomponentEffectStartTime: number=-1.1;
3737
exportletcomponentEffectEndTime: number=-1.1;
3838

39+
exportletblockingClampTime: number=-0;
3940
exportletblockingUpdateTime: number=-1.1;// First sync setState scheduled.
4041
exportletblockingEventTime: number=-1.1;// Event timeStamp of the first setState.
4142
export letblockingEventType: null|string=null;// Event type of the first setState.
43+
exportletblockingEventIsRepeat: boolean=false;
4244
// TODO: This should really be one per Transition lane.
45+
exportlettransitionClampTime: number=-0;
4346
exportlettransitionStartTime: number=-1.1;// First startTransition call before setState.
4447
exportlettransitionUpdateTime: number=-1.1;// First transition setState scheduled.
4548
exportlettransitionEventTime: number=-1.1;// Event timeStamp of the first transition.
4649
export lettransitionEventType: null|string=null;// Event type of the first transition.
50+
exportlettransitionEventIsRepeat: boolean=false;
4751

4852
exportfunctionstartUpdateTimerByLane(lane: Lane): void{
4953
if(!enableProfilerTimer||!enableComponentPerformanceTrack){
@@ -52,15 +56,25 @@ export function startUpdateTimerByLane(lane: Lane): void {
5256
if(isSyncLane(lane)||isBlockingLane(lane)){
5357
if(blockingUpdateTime<0){
5458
blockingUpdateTime=now();
55-
blockingEventTime=resolveEventTimeStamp();
56-
blockingEventType=resolveEventType();
59+
constnewEventTime=resolveEventTimeStamp();
60+
constnewEventType=resolveEventType();
61+
blockingEventIsRepeat=
62+
newEventTime===blockingEventTime&&
63+
newEventType===blockingEventType;
64+
blockingEventTime=newEventTime;
65+
blockingEventType=newEventType;
5766
}
5867
}elseif(isTransitionLane(lane)){
5968
if(transitionUpdateTime<0){
6069
transitionUpdateTime=now();
6170
if(transitionStartTime<0){
62-
transitionEventTime=resolveEventTimeStamp();
63-
transitionEventType=resolveEventType();
71+
constnewEventTime=resolveEventTimeStamp();
72+
constnewEventType=resolveEventType();
73+
transitionEventIsRepeat=
74+
newEventTime===transitionEventTime&&
75+
newEventType===transitionEventType;
76+
transitionEventTime=newEventTime;
77+
transitionEventType=newEventType;
6478
}
6579
}
6680
}
@@ -76,8 +90,13 @@ export function startAsyncTransitionTimer(): void {
7690
}
7791
if(transitionStartTime<0&&transitionUpdateTime<0){
7892
transitionStartTime=now();
79-
transitionEventTime=resolveEventTimeStamp();
80-
transitionEventType=resolveEventType();
93+
constnewEventTime=resolveEventTimeStamp();
94+
constnewEventType=resolveEventType();
95+
transitionEventIsRepeat=
96+
newEventTime===transitionEventTime&&
97+
newEventType===transitionEventType;
98+
transitionEventTime=newEventTime;
99+
transitionEventType=newEventType;
81100
}
82101
}
83102

@@ -115,12 +134,7 @@ export function clampBlockingTimers(finalTime: number): void {
115134
// If we had new updates come in while we were still rendering or committing, we don't want
116135
// those update times to create overlapping tracks in the performance timeline so we clamp
117136
// them to the end of the commit phase.
118-
if(blockingUpdateTime>=0&&blockingUpdateTime<finalTime){
119-
blockingUpdateTime=finalTime;
120-
}
121-
if(blockingEventTime>=0&&blockingEventTime<finalTime){
122-
blockingEventTime=finalTime;
123-
}
137+
blockingClampTime=finalTime;
124138
}
125139

126140
exportfunctionclampTransitionTimers(finalTime: number): void{
@@ -130,15 +144,7 @@ export function clampTransitionTimers(finalTime: number): void {
130144
// If we had new updates come in while we were still rendering or committing, we don't want
131145
// those update times to create overlapping tracks in the performance timeline so we clamp
132146
// them to the end of the commit phase.
133-
if(transitionStartTime>=0&&transitionStartTime<finalTime){
134-
transitionStartTime=finalTime;
135-
}
136-
if(transitionUpdateTime>=0&&transitionUpdateTime<finalTime){
137-
transitionUpdateTime=finalTime;
138-
}
139-
if(transitionEventTime>=0&&transitionEventTime<finalTime){
140-
transitionEventTime=finalTime;
141-
}
147+
transitionClampTime=finalTime;
142148
}
143149

144150
exportfunctionpushNestedEffectDurations(): number{

‎packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('ReactFiberHostContext', () => {
8383
}
8484
returnDefaultEventPriority;
8585
},
86+
trackSchedulerEvent: function(){},
8687
resolveEventType: function(){
8788
returnnull;
8889
},

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit c13986d

Browse files
authored
Fix Overlapping "message" Bug in Performance Track (#31528)
When you schedule a microtask from render or effect and then call setState (or ping) from there, the "event" is the event that React scheduled (which will be a postMessage). The event time of this new render will be before the last render finished. We usually clamp these but in this scenario the update doesn't happen while a render is happening. Causing overlapping events. Before: <img width="1229" alt="Screenshot 2024-11-12 at 11 01 30 PM" src="https://github.com/user-attachments/assets/9652cf3b-b358-453c-b295-1239cbb15952"> Therefore when we finalize a render we need to store the end of the last render so when we a new update comes in later with an event time earlier than that, we know to clamp it. There's also a special case here where when we enter the `RootDidNotComplete` or `RootSuspendedWithDelay` case we neither leave the root as in progress nor commit it. Those needs to finalize too. Really this should be modeled as a suspended track that we haven't added yet. That's the gap between "Blocked" and "message" below. After: <img width="1471" alt="Screenshot 2024-11-13 at 12 31 34 AM" src="https://github.com/user-attachments/assets/b24f994e-9055-4b10-ad29-ad9b36302ffc"> I also fixed an issue where we may log the same event name multiple times if we're rendering more than once in the same event. In this case I just leave a blank trace between the last commit and the next update. I also adding ignoring of the "message" event at all in these cases when the event is from React's scheduling itself.
1 parent 4686872 commit c13986d

12 files changed

Lines changed: 97 additions & 31 deletions

File tree

‎packages/react-art/src/ReactFiberConfigART.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ export function resolveUpdatePriority(): EventPriority {
363363
returncurrentUpdatePriority||DefaultEventPriority;
364364
}
365365

366+
exportfunctiontrackSchedulerEvent(): void{}
367+
366368
export functionresolveEventType(): null|string{
367369
returnnull;
368370
}

‎packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,19 @@ export function shouldAttemptEagerTransition(): boolean {
606606
returnfalse;
607607
}
608608

609+
letschedulerEvent: void|Event=undefined;
610+
exportfunctiontrackSchedulerEvent(): void{
611+
schedulerEvent=window.event;
612+
}
613+
609614
export functionresolveEventType(): null|string{
610615
constevent=window.event;
611-
returnevent ? event.type : null;
616+
returnevent&&event!==schedulerEvent? event.type : null;
612617
}
613618

614619
exportfunctionresolveEventTimeStamp(): number{
615620
constevent=window.event;
616-
returnevent ? event.timeStamp : -1.1;
621+
returnevent&&event!==schedulerEvent? event.timeStamp : -1.1;
617622
}
618623

619624
exportconstisPrimaryRenderer=true;

‎packages/react-native-renderer/src/ReactFiberConfigFabric.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ export function resolveUpdatePriority(): EventPriority {
372372
returnDefaultEventPriority;
373373
}
374374

375+
exportfunctiontrackSchedulerEvent(): void{}
376+
375377
export functionresolveEventType(): null|string{
376378
returnnull;
377379
}

‎packages/react-native-renderer/src/ReactFiberConfigNative.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ export function resolveUpdatePriority(): EventPriority {
288288
returnDefaultEventPriority;
289289
}
290290

291+
exportfunctiontrackSchedulerEvent(): void{}
292+
291293
export functionresolveEventType(): null|string{
292294
returnnull;
293295
}

‎packages/react-noop-renderer/src/createReactNoop.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
531531
returncurrentEventPriority;
532532
},
533533

534+
trackSchedulerEvent(): void{},
535+
534536
resolveEventType(): null|string{
535537
return null;
536538
},

‎packages/react-reconciler/src/ReactFiberPerformanceTrack.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export function logBlockingStart(
118118
updateTime: number,
119119
eventTime: number,
120120
eventType: null|string,
121+
eventIsRepeat: boolean,
121122
renderStartTime: number,
122123
): void{
123124
if(supportsUserTiming){
@@ -127,7 +128,7 @@ export function logBlockingStart(
127128
reusableLaneDevToolDetails.color='secondary-dark';
128129
reusableLaneOptions.start=eventTime;
129130
reusableLaneOptions.end=updateTime>0 ? updateTime : renderStartTime;
130-
performance.measure(eventType,reusableLaneOptions);
131+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
131132
}
132133
if(updateTime>0){
133134
// Log the time from when we called setState until we started rendering.
@@ -144,6 +145,7 @@ export function logTransitionStart(
144145
updateTime: number,
145146
eventTime: number,
146147
eventType: null|string,
148+
eventIsRepeat: boolean,
147149
renderStartTime: number,
148150
): void{
149151
if(supportsUserTiming){
@@ -158,7 +160,7 @@ export function logTransitionStart(
158160
: updateTime>0
159161
? updateTime
160162
: renderStartTime;
161-
performance.measure(eventType,reusableLaneOptions);
163+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
162164
}
163165
if(startTime>0){
164166
// Log the time from when we started an async transition until we called setState or started rendering.

‎packages/react-reconciler/src/ReactFiberRootScheduler.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
disableSchedulerTimeoutInWorkLoop,
1919
enableProfilerTimer,
2020
enableProfilerNestedUpdatePhase,
21+
enableComponentPerformanceTrack,
2122
enableSiblingPrerendering,
2223
}from'shared/ReactFeatureFlags';
2324
import{
@@ -64,6 +65,7 @@ import {
6465
supportsMicrotasks,
6566
scheduleMicrotask,
6667
shouldAttemptEagerTransition,
68+
trackSchedulerEvent,
6769
}from'./ReactFiberConfig';
6870

6971
importReactSharedInternalsfrom'shared/ReactSharedInternals';
@@ -225,6 +227,12 @@ function flushSyncWorkAcrossRoots_impl(
225227
}
226228

227229
functionprocessRootScheduleInMicrotask(){
230+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
231+
// Track the currently executing event if there is one so we can ignore this
232+
// event when logging events.
233+
trackSchedulerEvent();
234+
}
235+
228236
// This function is always called inside a microtask. It should never be
229237
// called synchronously.
230238
didScheduleMicrotask=false;
@@ -428,6 +436,12 @@ function performWorkOnRootViaSchedulerTask(
428436
resetNestedUpdateFlag();
429437
}
430438

439+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
440+
// Track the currently executing event if there is one so we can ignore this
441+
// event when logging events.
442+
trackSchedulerEvent();
443+
}
444+
431445
// Flush any pending passive effects before deciding which lanes to work on,
432446
// in case they schedule additional work.
433447
constoriginalCallbackNode=root.callbackNode;

‎packages/react-reconciler/src/ReactFiberWorkLoop.js‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
setCurrentUpdatePriority,
9191
getCurrentUpdatePriority,
9292
resolveUpdatePriority,
93+
trackSchedulerEvent,
9394
}from'./ReactFiberConfig';
9495

9596
import{createWorkInProgress,resetWorkInProgress}from'./ReactFiber';
@@ -229,13 +230,17 @@ import {
229230
}from'./ReactFiberConcurrentUpdates';
230231

231232
import{
233+
blockingClampTime,
232234
blockingUpdateTime,
233235
blockingEventTime,
234236
blockingEventType,
237+
blockingEventIsRepeat,
238+
transitionClampTime,
235239
transitionStartTime,
236240
transitionUpdateTime,
237241
transitionEventTime,
238242
transitionEventType,
243+
transitionEventIsRepeat,
239244
clearBlockingTimers,
240245
clearTransitionTimers,
241246
clampBlockingTimers,
@@ -938,6 +943,9 @@ export function performWorkOnRoot(
938943
}
939944
break;
940945
}elseif(exitStatus===RootDidNotComplete){
946+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
947+
finalizeRender(lanes,now());
948+
}
941949
// The render unwound without completing the tree. This happens in special
942950
// cases where need to exit the current render without producing a
943951
// consistent tree or committing.
@@ -1130,6 +1138,9 @@ function finishConcurrentRender(
11301138
// This is a transition, so we should exit without committing a
11311139
// placeholder and without scheduling a timeout. Delay indefinitely
11321140
// until we receive more data.
1141+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
1142+
finalizeRender(lanes,now());
1143+
}
11331144
constdidAttemptEntireTree=
11341145
!workInProgressRootDidSkipSuspendedSiblings;
11351146
markRootSuspended(
@@ -1655,19 +1666,31 @@ function prepareFreshStack(root: FiberRoot, lanes: Lanes): Fiber {
16551666

16561667
if(includesSyncLane(lanes)||includesBlockingLane(lanes)){
16571668
logBlockingStart(
1658-
blockingUpdateTime,
1659-
blockingEventTime,
1669+
blockingUpdateTime>=0&&blockingUpdateTime<blockingClampTime
1670+
? blockingClampTime
1671+
: blockingUpdateTime,
1672+
blockingEventTime>=0&&blockingEventTime<blockingClampTime
1673+
? blockingClampTime
1674+
: blockingEventTime,
16601675
blockingEventType,
1676+
blockingEventIsRepeat,
16611677
renderStartTime,
16621678
);
16631679
clearBlockingTimers();
16641680
}
16651681
if(includesTransitionLane(lanes)){
16661682
logTransitionStart(
1667-
transitionStartTime,
1668-
transitionUpdateTime,
1669-
transitionEventTime,
1683+
transitionStartTime>=0&&transitionStartTime<transitionClampTime
1684+
? transitionClampTime
1685+
: transitionStartTime,
1686+
transitionUpdateTime>=0&&transitionUpdateTime<transitionClampTime
1687+
? transitionClampTime
1688+
: transitionUpdateTime,
1689+
transitionEventTime>=0&&transitionEventTime<transitionClampTime
1690+
? transitionClampTime
1691+
: transitionEventTime,
16701692
transitionEventType,
1693+
transitionEventIsRepeat,
16711694
renderStartTime,
16721695
);
16731696
clearTransitionTimers();
@@ -3139,6 +3162,11 @@ function commitRootImpl(
31393162
// with setTimeout
31403163
pendingPassiveTransitions=transitions;
31413164
scheduleCallback(NormalSchedulerPriority,()=>{
3165+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
3166+
// Track the currently executing event if there is one so we can ignore this
3167+
// event when logging events.
3168+
trackSchedulerEvent();
3169+
}
31423170
flushPassiveEffects(true);
31433171
// This render triggered passive effects: release the root cache pool
31443172
// *after* passive effects fire to avoid freeing a cache pool that may

‎packages/react-reconciler/src/ReactProfilerTimer.js‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ export let componentEffectDuration: number = -0;
3636
exportletcomponentEffectStartTime: number=-1.1;
3737
exportletcomponentEffectEndTime: number=-1.1;
3838

39+
exportletblockingClampTime: number=-0;
3940
exportletblockingUpdateTime: number=-1.1;// First sync setState scheduled.
4041
exportletblockingEventTime: number=-1.1;// Event timeStamp of the first setState.
4142
export letblockingEventType: null|string=null;// Event type of the first setState.
43+
exportletblockingEventIsRepeat: boolean=false;
4244
// TODO: This should really be one per Transition lane.
45+
exportlettransitionClampTime: number=-0;
4346
exportlettransitionStartTime: number=-1.1;// First startTransition call before setState.
4447
exportlettransitionUpdateTime: number=-1.1;// First transition setState scheduled.
4548
exportlettransitionEventTime: number=-1.1;// Event timeStamp of the first transition.
4649
export lettransitionEventType: null|string=null;// Event type of the first transition.
50+
exportlettransitionEventIsRepeat: boolean=false;
4751

4852
exportfunctionstartUpdateTimerByLane(lane: Lane): void{
4953
if(!enableProfilerTimer||!enableComponentPerformanceTrack){
@@ -52,15 +56,25 @@ export function startUpdateTimerByLane(lane: Lane): void {
5256
if(isSyncLane(lane)||isBlockingLane(lane)){
5357
if(blockingUpdateTime<0){
5458
blockingUpdateTime=now();
55-
blockingEventTime=resolveEventTimeStamp();
56-
blockingEventType=resolveEventType();
59+
constnewEventTime=resolveEventTimeStamp();
60+
constnewEventType=resolveEventType();
61+
blockingEventIsRepeat=
62+
newEventTime===blockingEventTime&&
63+
newEventType===blockingEventType;
64+
blockingEventTime=newEventTime;
65+
blockingEventType=newEventType;
5766
}
5867
}elseif(isTransitionLane(lane)){
5968
if(transitionUpdateTime<0){
6069
transitionUpdateTime=now();
6170
if(transitionStartTime<0){
62-
transitionEventTime=resolveEventTimeStamp();
63-
transitionEventType=resolveEventType();
71+
constnewEventTime=resolveEventTimeStamp();
72+
constnewEventType=resolveEventType();
73+
transitionEventIsRepeat=
74+
newEventTime===transitionEventTime&&
75+
newEventType===transitionEventType;
76+
transitionEventTime=newEventTime;
77+
transitionEventType=newEventType;
6478
}
6579
}
6680
}
@@ -76,8 +90,13 @@ export function startAsyncTransitionTimer(): void {
7690
}
7791
if(transitionStartTime<0&&transitionUpdateTime<0){
7892
transitionStartTime=now();
79-
transitionEventTime=resolveEventTimeStamp();
80-
transitionEventType=resolveEventType();
93+
constnewEventTime=resolveEventTimeStamp();
94+
constnewEventType=resolveEventType();
95+
transitionEventIsRepeat=
96+
newEventTime===transitionEventTime&&
97+
newEventType===transitionEventType;
98+
transitionEventTime=newEventTime;
99+
transitionEventType=newEventType;
81100
}
82101
}
83102

@@ -115,12 +134,7 @@ export function clampBlockingTimers(finalTime: number): void {
115134
// If we had new updates come in while we were still rendering or committing, we don't want
116135
// those update times to create overlapping tracks in the performance timeline so we clamp
117136
// them to the end of the commit phase.
118-
if(blockingUpdateTime>=0&&blockingUpdateTime<finalTime){
119-
blockingUpdateTime=finalTime;
120-
}
121-
if(blockingEventTime>=0&&blockingEventTime<finalTime){
122-
blockingEventTime=finalTime;
123-
}
137+
blockingClampTime=finalTime;
124138
}
125139

126140
exportfunctionclampTransitionTimers(finalTime: number): void{
@@ -130,15 +144,7 @@ export function clampTransitionTimers(finalTime: number): void {
130144
// If we had new updates come in while we were still rendering or committing, we don't want
131145
// those update times to create overlapping tracks in the performance timeline so we clamp
132146
// them to the end of the commit phase.
133-
if(transitionStartTime>=0&&transitionStartTime<finalTime){
134-
transitionStartTime=finalTime;
135-
}
136-
if(transitionUpdateTime>=0&&transitionUpdateTime<finalTime){
137-
transitionUpdateTime=finalTime;
138-
}
139-
if(transitionEventTime>=0&&transitionEventTime<finalTime){
140-
transitionEventTime=finalTime;
141-
}
147+
transitionClampTime=finalTime;
142148
}
143149

144150
exportfunctionpushNestedEffectDurations(): number{

‎packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('ReactFiberHostContext', () => {
8383
}
8484
returnDefaultEventPriority;
8585
},
86+
trackSchedulerEvent: function(){},
8687
resolveEventType: function(){
8788
returnnull;
8889
},

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit c13986d

Browse files
authored
Fix Overlapping "message" Bug in Performance Track (#31528)
When you schedule a microtask from render or effect and then call setState (or ping) from there, the "event" is the event that React scheduled (which will be a postMessage). The event time of this new render will be before the last render finished. We usually clamp these but in this scenario the update doesn't happen while a render is happening. Causing overlapping events. Before: <img width="1229" alt="Screenshot 2024-11-12 at 11 01 30 PM" src="https://github.com/user-attachments/assets/9652cf3b-b358-453c-b295-1239cbb15952"> Therefore when we finalize a render we need to store the end of the last render so when we a new update comes in later with an event time earlier than that, we know to clamp it. There's also a special case here where when we enter the `RootDidNotComplete` or `RootSuspendedWithDelay` case we neither leave the root as in progress nor commit it. Those needs to finalize too. Really this should be modeled as a suspended track that we haven't added yet. That's the gap between "Blocked" and "message" below. After: <img width="1471" alt="Screenshot 2024-11-13 at 12 31 34 AM" src="https://github.com/user-attachments/assets/b24f994e-9055-4b10-ad29-ad9b36302ffc"> I also fixed an issue where we may log the same event name multiple times if we're rendering more than once in the same event. In this case I just leave a blank trace between the last commit and the next update. I also adding ignoring of the "message" event at all in these cases when the event is from React's scheduling itself.
1 parent 4686872 commit c13986d

12 files changed

Lines changed: 97 additions & 31 deletions

File tree

‎packages/react-art/src/ReactFiberConfigART.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ export function resolveUpdatePriority(): EventPriority {
363363
returncurrentUpdatePriority||DefaultEventPriority;
364364
}
365365

366+
exportfunctiontrackSchedulerEvent(): void{}
367+
366368
export functionresolveEventType(): null|string{
367369
returnnull;
368370
}

‎packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,19 @@ export function shouldAttemptEagerTransition(): boolean {
606606
returnfalse;
607607
}
608608

609+
letschedulerEvent: void|Event=undefined;
610+
exportfunctiontrackSchedulerEvent(): void{
611+
schedulerEvent=window.event;
612+
}
613+
609614
export functionresolveEventType(): null|string{
610615
constevent=window.event;
611-
returnevent ? event.type : null;
616+
returnevent&&event!==schedulerEvent? event.type : null;
612617
}
613618

614619
exportfunctionresolveEventTimeStamp(): number{
615620
constevent=window.event;
616-
returnevent ? event.timeStamp : -1.1;
621+
returnevent&&event!==schedulerEvent? event.timeStamp : -1.1;
617622
}
618623

619624
exportconstisPrimaryRenderer=true;

‎packages/react-native-renderer/src/ReactFiberConfigFabric.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ export function resolveUpdatePriority(): EventPriority {
372372
returnDefaultEventPriority;
373373
}
374374

375+
exportfunctiontrackSchedulerEvent(): void{}
376+
375377
export functionresolveEventType(): null|string{
376378
returnnull;
377379
}

‎packages/react-native-renderer/src/ReactFiberConfigNative.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ export function resolveUpdatePriority(): EventPriority {
288288
returnDefaultEventPriority;
289289
}
290290

291+
exportfunctiontrackSchedulerEvent(): void{}
292+
291293
export functionresolveEventType(): null|string{
292294
returnnull;
293295
}

‎packages/react-noop-renderer/src/createReactNoop.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
531531
returncurrentEventPriority;
532532
},
533533

534+
trackSchedulerEvent(): void{},
535+
534536
resolveEventType(): null|string{
535537
return null;
536538
},

‎packages/react-reconciler/src/ReactFiberPerformanceTrack.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export function logBlockingStart(
118118
updateTime: number,
119119
eventTime: number,
120120
eventType: null|string,
121+
eventIsRepeat: boolean,
121122
renderStartTime: number,
122123
): void{
123124
if(supportsUserTiming){
@@ -127,7 +128,7 @@ export function logBlockingStart(
127128
reusableLaneDevToolDetails.color='secondary-dark';
128129
reusableLaneOptions.start=eventTime;
129130
reusableLaneOptions.end=updateTime>0 ? updateTime : renderStartTime;
130-
performance.measure(eventType,reusableLaneOptions);
131+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
131132
}
132133
if(updateTime>0){
133134
// Log the time from when we called setState until we started rendering.
@@ -144,6 +145,7 @@ export function logTransitionStart(
144145
updateTime: number,
145146
eventTime: number,
146147
eventType: null|string,
148+
eventIsRepeat: boolean,
147149
renderStartTime: number,
148150
): void{
149151
if(supportsUserTiming){
@@ -158,7 +160,7 @@ export function logTransitionStart(
158160
: updateTime>0
159161
? updateTime
160162
: renderStartTime;
161-
performance.measure(eventType,reusableLaneOptions);
163+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
162164
}
163165
if(startTime>0){
164166
// Log the time from when we started an async transition until we called setState or started rendering.

‎packages/react-reconciler/src/ReactFiberRootScheduler.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
disableSchedulerTimeoutInWorkLoop,
1919
enableProfilerTimer,
2020
enableProfilerNestedUpdatePhase,
21+
enableComponentPerformanceTrack,
2122
enableSiblingPrerendering,
2223
}from'shared/ReactFeatureFlags';
2324
import{
@@ -64,6 +65,7 @@ import {
6465
supportsMicrotasks,
6566
scheduleMicrotask,
6667
shouldAttemptEagerTransition,
68+
trackSchedulerEvent,
6769
}from'./ReactFiberConfig';
6870

6971
importReactSharedInternalsfrom'shared/ReactSharedInternals';
@@ -225,6 +227,12 @@ function flushSyncWorkAcrossRoots_impl(
225227
}
226228

227229
functionprocessRootScheduleInMicrotask(){
230+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
231+
// Track the currently executing event if there is one so we can ignore this
232+
// event when logging events.
233+
trackSchedulerEvent();
234+
}
235+
228236
// This function is always called inside a microtask. It should never be
229237
// called synchronously.
230238
didScheduleMicrotask=false;
@@ -428,6 +436,12 @@ function performWorkOnRootViaSchedulerTask(
428436
resetNestedUpdateFlag();
429437
}
430438

439+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
440+
// Track the currently executing event if there is one so we can ignore this
441+
// event when logging events.
442+
trackSchedulerEvent();
443+
}
444+
431445
// Flush any pending passive effects before deciding which lanes to work on,
432446
// in case they schedule additional work.
433447
constoriginalCallbackNode=root.callbackNode;

‎packages/react-reconciler/src/ReactFiberWorkLoop.js‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
setCurrentUpdatePriority,
9191
getCurrentUpdatePriority,
9292
resolveUpdatePriority,
93+
trackSchedulerEvent,
9394
}from'./ReactFiberConfig';
9495

9596
import{createWorkInProgress,resetWorkInProgress}from'./ReactFiber';
@@ -229,13 +230,17 @@ import {
229230
}from'./ReactFiberConcurrentUpdates';
230231

231232
import{
233+
blockingClampTime,
232234
blockingUpdateTime,
233235
blockingEventTime,
234236
blockingEventType,
237+
blockingEventIsRepeat,
238+
transitionClampTime,
235239
transitionStartTime,
236240
transitionUpdateTime,
237241
transitionEventTime,
238242
transitionEventType,
243+
transitionEventIsRepeat,
239244
clearBlockingTimers,
240245
clearTransitionTimers,
241246
clampBlockingTimers,
@@ -938,6 +943,9 @@ export function performWorkOnRoot(
938943
}
939944
break;
940945
}elseif(exitStatus===RootDidNotComplete){
946+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
947+
finalizeRender(lanes,now());
948+
}
941949
// The render unwound without completing the tree. This happens in special
942950
// cases where need to exit the current render without producing a
943951
// consistent tree or committing.
@@ -1130,6 +1138,9 @@ function finishConcurrentRender(
11301138
// This is a transition, so we should exit without committing a
11311139
// placeholder and without scheduling a timeout. Delay indefinitely
11321140
// until we receive more data.
1141+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
1142+
finalizeRender(lanes,now());
1143+
}
11331144
constdidAttemptEntireTree=
11341145
!workInProgressRootDidSkipSuspendedSiblings;
11351146
markRootSuspended(
@@ -1655,19 +1666,31 @@ function prepareFreshStack(root: FiberRoot, lanes: Lanes): Fiber {
16551666

16561667
if(includesSyncLane(lanes)||includesBlockingLane(lanes)){
16571668
logBlockingStart(
1658-
blockingUpdateTime,
1659-
blockingEventTime,
1669+
blockingUpdateTime>=0&&blockingUpdateTime<blockingClampTime
1670+
? blockingClampTime
1671+
: blockingUpdateTime,
1672+
blockingEventTime>=0&&blockingEventTime<blockingClampTime
1673+
? blockingClampTime
1674+
: blockingEventTime,
16601675
blockingEventType,
1676+
blockingEventIsRepeat,
16611677
renderStartTime,
16621678
);
16631679
clearBlockingTimers();
16641680
}
16651681
if(includesTransitionLane(lanes)){
16661682
logTransitionStart(
1667-
transitionStartTime,
1668-
transitionUpdateTime,
1669-
transitionEventTime,
1683+
transitionStartTime>=0&&transitionStartTime<transitionClampTime
1684+
? transitionClampTime
1685+
: transitionStartTime,
1686+
transitionUpdateTime>=0&&transitionUpdateTime<transitionClampTime
1687+
? transitionClampTime
1688+
: transitionUpdateTime,
1689+
transitionEventTime>=0&&transitionEventTime<transitionClampTime
1690+
? transitionClampTime
1691+
: transitionEventTime,
16701692
transitionEventType,
1693+
transitionEventIsRepeat,
16711694
renderStartTime,
16721695
);
16731696
clearTransitionTimers();
@@ -3139,6 +3162,11 @@ function commitRootImpl(
31393162
// with setTimeout
31403163
pendingPassiveTransitions=transitions;
31413164
scheduleCallback(NormalSchedulerPriority,()=>{
3165+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
3166+
// Track the currently executing event if there is one so we can ignore this
3167+
// event when logging events.
3168+
trackSchedulerEvent();
3169+
}
31423170
flushPassiveEffects(true);
31433171
// This render triggered passive effects: release the root cache pool
31443172
// *after* passive effects fire to avoid freeing a cache pool that may

‎packages/react-reconciler/src/ReactProfilerTimer.js‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ export let componentEffectDuration: number = -0;
3636
exportletcomponentEffectStartTime: number=-1.1;
3737
exportletcomponentEffectEndTime: number=-1.1;
3838

39+
exportletblockingClampTime: number=-0;
3940
exportletblockingUpdateTime: number=-1.1;// First sync setState scheduled.
4041
exportletblockingEventTime: number=-1.1;// Event timeStamp of the first setState.
4142
export letblockingEventType: null|string=null;// Event type of the first setState.
43+
exportletblockingEventIsRepeat: boolean=false;
4244
// TODO: This should really be one per Transition lane.
45+
exportlettransitionClampTime: number=-0;
4346
exportlettransitionStartTime: number=-1.1;// First startTransition call before setState.
4447
exportlettransitionUpdateTime: number=-1.1;// First transition setState scheduled.
4548
exportlettransitionEventTime: number=-1.1;// Event timeStamp of the first transition.
4649
export lettransitionEventType: null|string=null;// Event type of the first transition.
50+
exportlettransitionEventIsRepeat: boolean=false;
4751

4852
exportfunctionstartUpdateTimerByLane(lane: Lane): void{
4953
if(!enableProfilerTimer||!enableComponentPerformanceTrack){
@@ -52,15 +56,25 @@ export function startUpdateTimerByLane(lane: Lane): void {
5256
if(isSyncLane(lane)||isBlockingLane(lane)){
5357
if(blockingUpdateTime<0){
5458
blockingUpdateTime=now();
55-
blockingEventTime=resolveEventTimeStamp();
56-
blockingEventType=resolveEventType();
59+
constnewEventTime=resolveEventTimeStamp();
60+
constnewEventType=resolveEventType();
61+
blockingEventIsRepeat=
62+
newEventTime===blockingEventTime&&
63+
newEventType===blockingEventType;
64+
blockingEventTime=newEventTime;
65+
blockingEventType=newEventType;
5766
}
5867
}elseif(isTransitionLane(lane)){
5968
if(transitionUpdateTime<0){
6069
transitionUpdateTime=now();
6170
if(transitionStartTime<0){
62-
transitionEventTime=resolveEventTimeStamp();
63-
transitionEventType=resolveEventType();
71+
constnewEventTime=resolveEventTimeStamp();
72+
constnewEventType=resolveEventType();
73+
transitionEventIsRepeat=
74+
newEventTime===transitionEventTime&&
75+
newEventType===transitionEventType;
76+
transitionEventTime=newEventTime;
77+
transitionEventType=newEventType;
6478
}
6579
}
6680
}
@@ -76,8 +90,13 @@ export function startAsyncTransitionTimer(): void {
7690
}
7791
if(transitionStartTime<0&&transitionUpdateTime<0){
7892
transitionStartTime=now();
79-
transitionEventTime=resolveEventTimeStamp();
80-
transitionEventType=resolveEventType();
93+
constnewEventTime=resolveEventTimeStamp();
94+
constnewEventType=resolveEventType();
95+
transitionEventIsRepeat=
96+
newEventTime===transitionEventTime&&
97+
newEventType===transitionEventType;
98+
transitionEventTime=newEventTime;
99+
transitionEventType=newEventType;
81100
}
82101
}
83102

@@ -115,12 +134,7 @@ export function clampBlockingTimers(finalTime: number): void {
115134
// If we had new updates come in while we were still rendering or committing, we don't want
116135
// those update times to create overlapping tracks in the performance timeline so we clamp
117136
// them to the end of the commit phase.
118-
if(blockingUpdateTime>=0&&blockingUpdateTime<finalTime){
119-
blockingUpdateTime=finalTime;
120-
}
121-
if(blockingEventTime>=0&&blockingEventTime<finalTime){
122-
blockingEventTime=finalTime;
123-
}
137+
blockingClampTime=finalTime;
124138
}
125139

126140
exportfunctionclampTransitionTimers(finalTime: number): void{
@@ -130,15 +144,7 @@ export function clampTransitionTimers(finalTime: number): void {
130144
// If we had new updates come in while we were still rendering or committing, we don't want
131145
// those update times to create overlapping tracks in the performance timeline so we clamp
132146
// them to the end of the commit phase.
133-
if(transitionStartTime>=0&&transitionStartTime<finalTime){
134-
transitionStartTime=finalTime;
135-
}
136-
if(transitionUpdateTime>=0&&transitionUpdateTime<finalTime){
137-
transitionUpdateTime=finalTime;
138-
}
139-
if(transitionEventTime>=0&&transitionEventTime<finalTime){
140-
transitionEventTime=finalTime;
141-
}
147+
transitionClampTime=finalTime;
142148
}
143149

144150
exportfunctionpushNestedEffectDurations(): number{

‎packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('ReactFiberHostContext', () => {
8383
}
8484
returnDefaultEventPriority;
8585
},
86+
trackSchedulerEvent: function(){},
8687
resolveEventType: function(){
8788
returnnull;
8889
},

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit c13986d

Browse files
authored
Fix Overlapping "message" Bug in Performance Track (#31528)
When you schedule a microtask from render or effect and then call setState (or ping) from there, the "event" is the event that React scheduled (which will be a postMessage). The event time of this new render will be before the last render finished. We usually clamp these but in this scenario the update doesn't happen while a render is happening. Causing overlapping events. Before: <img width="1229" alt="Screenshot 2024-11-12 at 11 01 30 PM" src="https://github.com/user-attachments/assets/9652cf3b-b358-453c-b295-1239cbb15952"> Therefore when we finalize a render we need to store the end of the last render so when we a new update comes in later with an event time earlier than that, we know to clamp it. There's also a special case here where when we enter the `RootDidNotComplete` or `RootSuspendedWithDelay` case we neither leave the root as in progress nor commit it. Those needs to finalize too. Really this should be modeled as a suspended track that we haven't added yet. That's the gap between "Blocked" and "message" below. After: <img width="1471" alt="Screenshot 2024-11-13 at 12 31 34 AM" src="https://github.com/user-attachments/assets/b24f994e-9055-4b10-ad29-ad9b36302ffc"> I also fixed an issue where we may log the same event name multiple times if we're rendering more than once in the same event. In this case I just leave a blank trace between the last commit and the next update. I also adding ignoring of the "message" event at all in these cases when the event is from React's scheduling itself.
1 parent 4686872 commit c13986d

12 files changed

Lines changed: 97 additions & 31 deletions

File tree

‎packages/react-art/src/ReactFiberConfigART.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ export function resolveUpdatePriority(): EventPriority {
363363
returncurrentUpdatePriority||DefaultEventPriority;
364364
}
365365

366+
exportfunctiontrackSchedulerEvent(): void{}
367+
366368
export functionresolveEventType(): null|string{
367369
returnnull;
368370
}

‎packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,19 @@ export function shouldAttemptEagerTransition(): boolean {
606606
returnfalse;
607607
}
608608

609+
letschedulerEvent: void|Event=undefined;
610+
exportfunctiontrackSchedulerEvent(): void{
611+
schedulerEvent=window.event;
612+
}
613+
609614
export functionresolveEventType(): null|string{
610615
constevent=window.event;
611-
returnevent ? event.type : null;
616+
returnevent&&event!==schedulerEvent? event.type : null;
612617
}
613618

614619
exportfunctionresolveEventTimeStamp(): number{
615620
constevent=window.event;
616-
returnevent ? event.timeStamp : -1.1;
621+
returnevent&&event!==schedulerEvent? event.timeStamp : -1.1;
617622
}
618623

619624
exportconstisPrimaryRenderer=true;

‎packages/react-native-renderer/src/ReactFiberConfigFabric.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ export function resolveUpdatePriority(): EventPriority {
372372
returnDefaultEventPriority;
373373
}
374374

375+
exportfunctiontrackSchedulerEvent(): void{}
376+
375377
export functionresolveEventType(): null|string{
376378
returnnull;
377379
}

‎packages/react-native-renderer/src/ReactFiberConfigNative.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ export function resolveUpdatePriority(): EventPriority {
288288
returnDefaultEventPriority;
289289
}
290290

291+
exportfunctiontrackSchedulerEvent(): void{}
292+
291293
export functionresolveEventType(): null|string{
292294
returnnull;
293295
}

‎packages/react-noop-renderer/src/createReactNoop.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
531531
returncurrentEventPriority;
532532
},
533533

534+
trackSchedulerEvent(): void{},
535+
534536
resolveEventType(): null|string{
535537
return null;
536538
},

‎packages/react-reconciler/src/ReactFiberPerformanceTrack.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export function logBlockingStart(
118118
updateTime: number,
119119
eventTime: number,
120120
eventType: null|string,
121+
eventIsRepeat: boolean,
121122
renderStartTime: number,
122123
): void{
123124
if(supportsUserTiming){
@@ -127,7 +128,7 @@ export function logBlockingStart(
127128
reusableLaneDevToolDetails.color='secondary-dark';
128129
reusableLaneOptions.start=eventTime;
129130
reusableLaneOptions.end=updateTime>0 ? updateTime : renderStartTime;
130-
performance.measure(eventType,reusableLaneOptions);
131+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
131132
}
132133
if(updateTime>0){
133134
// Log the time from when we called setState until we started rendering.
@@ -144,6 +145,7 @@ export function logTransitionStart(
144145
updateTime: number,
145146
eventTime: number,
146147
eventType: null|string,
148+
eventIsRepeat: boolean,
147149
renderStartTime: number,
148150
): void{
149151
if(supportsUserTiming){
@@ -158,7 +160,7 @@ export function logTransitionStart(
158160
: updateTime>0
159161
? updateTime
160162
: renderStartTime;
161-
performance.measure(eventType,reusableLaneOptions);
163+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
162164
}
163165
if(startTime>0){
164166
// Log the time from when we started an async transition until we called setState or started rendering.

‎packages/react-reconciler/src/ReactFiberRootScheduler.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
disableSchedulerTimeoutInWorkLoop,
1919
enableProfilerTimer,
2020
enableProfilerNestedUpdatePhase,
21+
enableComponentPerformanceTrack,
2122
enableSiblingPrerendering,
2223
}from'shared/ReactFeatureFlags';
2324
import{
@@ -64,6 +65,7 @@ import {
6465
supportsMicrotasks,
6566
scheduleMicrotask,
6667
shouldAttemptEagerTransition,
68+
trackSchedulerEvent,
6769
}from'./ReactFiberConfig';
6870

6971
importReactSharedInternalsfrom'shared/ReactSharedInternals';
@@ -225,6 +227,12 @@ function flushSyncWorkAcrossRoots_impl(
225227
}
226228

227229
functionprocessRootScheduleInMicrotask(){
230+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
231+
// Track the currently executing event if there is one so we can ignore this
232+
// event when logging events.
233+
trackSchedulerEvent();
234+
}
235+
228236
// This function is always called inside a microtask. It should never be
229237
// called synchronously.
230238
didScheduleMicrotask=false;
@@ -428,6 +436,12 @@ function performWorkOnRootViaSchedulerTask(
428436
resetNestedUpdateFlag();
429437
}
430438

439+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
440+
// Track the currently executing event if there is one so we can ignore this
441+
// event when logging events.
442+
trackSchedulerEvent();
443+
}
444+
431445
// Flush any pending passive effects before deciding which lanes to work on,
432446
// in case they schedule additional work.
433447
constoriginalCallbackNode=root.callbackNode;

‎packages/react-reconciler/src/ReactFiberWorkLoop.js‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
setCurrentUpdatePriority,
9191
getCurrentUpdatePriority,
9292
resolveUpdatePriority,
93+
trackSchedulerEvent,
9394
}from'./ReactFiberConfig';
9495

9596
import{createWorkInProgress,resetWorkInProgress}from'./ReactFiber';
@@ -229,13 +230,17 @@ import {
229230
}from'./ReactFiberConcurrentUpdates';
230231

231232
import{
233+
blockingClampTime,
232234
blockingUpdateTime,
233235
blockingEventTime,
234236
blockingEventType,
237+
blockingEventIsRepeat,
238+
transitionClampTime,
235239
transitionStartTime,
236240
transitionUpdateTime,
237241
transitionEventTime,
238242
transitionEventType,
243+
transitionEventIsRepeat,
239244
clearBlockingTimers,
240245
clearTransitionTimers,
241246
clampBlockingTimers,
@@ -938,6 +943,9 @@ export function performWorkOnRoot(
938943
}
939944
break;
940945
}elseif(exitStatus===RootDidNotComplete){
946+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
947+
finalizeRender(lanes,now());
948+
}
941949
// The render unwound without completing the tree. This happens in special
942950
// cases where need to exit the current render without producing a
943951
// consistent tree or committing.
@@ -1130,6 +1138,9 @@ function finishConcurrentRender(
11301138
// This is a transition, so we should exit without committing a
11311139
// placeholder and without scheduling a timeout. Delay indefinitely
11321140
// until we receive more data.
1141+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
1142+
finalizeRender(lanes,now());
1143+
}
11331144
constdidAttemptEntireTree=
11341145
!workInProgressRootDidSkipSuspendedSiblings;
11351146
markRootSuspended(
@@ -1655,19 +1666,31 @@ function prepareFreshStack(root: FiberRoot, lanes: Lanes): Fiber {
16551666

16561667
if(includesSyncLane(lanes)||includesBlockingLane(lanes)){
16571668
logBlockingStart(
1658-
blockingUpdateTime,
1659-
blockingEventTime,
1669+
blockingUpdateTime>=0&&blockingUpdateTime<blockingClampTime
1670+
? blockingClampTime
1671+
: blockingUpdateTime,
1672+
blockingEventTime>=0&&blockingEventTime<blockingClampTime
1673+
? blockingClampTime
1674+
: blockingEventTime,
16601675
blockingEventType,
1676+
blockingEventIsRepeat,
16611677
renderStartTime,
16621678
);
16631679
clearBlockingTimers();
16641680
}
16651681
if(includesTransitionLane(lanes)){
16661682
logTransitionStart(
1667-
transitionStartTime,
1668-
transitionUpdateTime,
1669-
transitionEventTime,
1683+
transitionStartTime>=0&&transitionStartTime<transitionClampTime
1684+
? transitionClampTime
1685+
: transitionStartTime,
1686+
transitionUpdateTime>=0&&transitionUpdateTime<transitionClampTime
1687+
? transitionClampTime
1688+
: transitionUpdateTime,
1689+
transitionEventTime>=0&&transitionEventTime<transitionClampTime
1690+
? transitionClampTime
1691+
: transitionEventTime,
16701692
transitionEventType,
1693+
transitionEventIsRepeat,
16711694
renderStartTime,
16721695
);
16731696
clearTransitionTimers();
@@ -3139,6 +3162,11 @@ function commitRootImpl(
31393162
// with setTimeout
31403163
pendingPassiveTransitions=transitions;
31413164
scheduleCallback(NormalSchedulerPriority,()=>{
3165+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
3166+
// Track the currently executing event if there is one so we can ignore this
3167+
// event when logging events.
3168+
trackSchedulerEvent();
3169+
}
31423170
flushPassiveEffects(true);
31433171
// This render triggered passive effects: release the root cache pool
31443172
// *after* passive effects fire to avoid freeing a cache pool that may

‎packages/react-reconciler/src/ReactProfilerTimer.js‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ export let componentEffectDuration: number = -0;
3636
exportletcomponentEffectStartTime: number=-1.1;
3737
exportletcomponentEffectEndTime: number=-1.1;
3838

39+
exportletblockingClampTime: number=-0;
3940
exportletblockingUpdateTime: number=-1.1;// First sync setState scheduled.
4041
exportletblockingEventTime: number=-1.1;// Event timeStamp of the first setState.
4142
export letblockingEventType: null|string=null;// Event type of the first setState.
43+
exportletblockingEventIsRepeat: boolean=false;
4244
// TODO: This should really be one per Transition lane.
45+
exportlettransitionClampTime: number=-0;
4346
exportlettransitionStartTime: number=-1.1;// First startTransition call before setState.
4447
exportlettransitionUpdateTime: number=-1.1;// First transition setState scheduled.
4548
exportlettransitionEventTime: number=-1.1;// Event timeStamp of the first transition.
4649
export lettransitionEventType: null|string=null;// Event type of the first transition.
50+
exportlettransitionEventIsRepeat: boolean=false;
4751

4852
exportfunctionstartUpdateTimerByLane(lane: Lane): void{
4953
if(!enableProfilerTimer||!enableComponentPerformanceTrack){
@@ -52,15 +56,25 @@ export function startUpdateTimerByLane(lane: Lane): void {
5256
if(isSyncLane(lane)||isBlockingLane(lane)){
5357
if(blockingUpdateTime<0){
5458
blockingUpdateTime=now();
55-
blockingEventTime=resolveEventTimeStamp();
56-
blockingEventType=resolveEventType();
59+
constnewEventTime=resolveEventTimeStamp();
60+
constnewEventType=resolveEventType();
61+
blockingEventIsRepeat=
62+
newEventTime===blockingEventTime&&
63+
newEventType===blockingEventType;
64+
blockingEventTime=newEventTime;
65+
blockingEventType=newEventType;
5766
}
5867
}elseif(isTransitionLane(lane)){
5968
if(transitionUpdateTime<0){
6069
transitionUpdateTime=now();
6170
if(transitionStartTime<0){
62-
transitionEventTime=resolveEventTimeStamp();
63-
transitionEventType=resolveEventType();
71+
constnewEventTime=resolveEventTimeStamp();
72+
constnewEventType=resolveEventType();
73+
transitionEventIsRepeat=
74+
newEventTime===transitionEventTime&&
75+
newEventType===transitionEventType;
76+
transitionEventTime=newEventTime;
77+
transitionEventType=newEventType;
6478
}
6579
}
6680
}
@@ -76,8 +90,13 @@ export function startAsyncTransitionTimer(): void {
7690
}
7791
if(transitionStartTime<0&&transitionUpdateTime<0){
7892
transitionStartTime=now();
79-
transitionEventTime=resolveEventTimeStamp();
80-
transitionEventType=resolveEventType();
93+
constnewEventTime=resolveEventTimeStamp();
94+
constnewEventType=resolveEventType();
95+
transitionEventIsRepeat=
96+
newEventTime===transitionEventTime&&
97+
newEventType===transitionEventType;
98+
transitionEventTime=newEventTime;
99+
transitionEventType=newEventType;
81100
}
82101
}
83102

@@ -115,12 +134,7 @@ export function clampBlockingTimers(finalTime: number): void {
115134
// If we had new updates come in while we were still rendering or committing, we don't want
116135
// those update times to create overlapping tracks in the performance timeline so we clamp
117136
// them to the end of the commit phase.
118-
if(blockingUpdateTime>=0&&blockingUpdateTime<finalTime){
119-
blockingUpdateTime=finalTime;
120-
}
121-
if(blockingEventTime>=0&&blockingEventTime<finalTime){
122-
blockingEventTime=finalTime;
123-
}
137+
blockingClampTime=finalTime;
124138
}
125139

126140
exportfunctionclampTransitionTimers(finalTime: number): void{
@@ -130,15 +144,7 @@ export function clampTransitionTimers(finalTime: number): void {
130144
// If we had new updates come in while we were still rendering or committing, we don't want
131145
// those update times to create overlapping tracks in the performance timeline so we clamp
132146
// them to the end of the commit phase.
133-
if(transitionStartTime>=0&&transitionStartTime<finalTime){
134-
transitionStartTime=finalTime;
135-
}
136-
if(transitionUpdateTime>=0&&transitionUpdateTime<finalTime){
137-
transitionUpdateTime=finalTime;
138-
}
139-
if(transitionEventTime>=0&&transitionEventTime<finalTime){
140-
transitionEventTime=finalTime;
141-
}
147+
transitionClampTime=finalTime;
142148
}
143149

144150
exportfunctionpushNestedEffectDurations(): number{

‎packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('ReactFiberHostContext', () => {
8383
}
8484
returnDefaultEventPriority;
8585
},
86+
trackSchedulerEvent: function(){},
8687
resolveEventType: function(){
8788
returnnull;
8889
},

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit c13986d

Browse files
authored
Fix Overlapping "message" Bug in Performance Track (#31528)
When you schedule a microtask from render or effect and then call setState (or ping) from there, the "event" is the event that React scheduled (which will be a postMessage). The event time of this new render will be before the last render finished. We usually clamp these but in this scenario the update doesn't happen while a render is happening. Causing overlapping events. Before: <img width="1229" alt="Screenshot 2024-11-12 at 11 01 30 PM" src="https://github.com/user-attachments/assets/9652cf3b-b358-453c-b295-1239cbb15952"> Therefore when we finalize a render we need to store the end of the last render so when we a new update comes in later with an event time earlier than that, we know to clamp it. There's also a special case here where when we enter the `RootDidNotComplete` or `RootSuspendedWithDelay` case we neither leave the root as in progress nor commit it. Those needs to finalize too. Really this should be modeled as a suspended track that we haven't added yet. That's the gap between "Blocked" and "message" below. After: <img width="1471" alt="Screenshot 2024-11-13 at 12 31 34 AM" src="https://github.com/user-attachments/assets/b24f994e-9055-4b10-ad29-ad9b36302ffc"> I also fixed an issue where we may log the same event name multiple times if we're rendering more than once in the same event. In this case I just leave a blank trace between the last commit and the next update. I also adding ignoring of the "message" event at all in these cases when the event is from React's scheduling itself.
1 parent 4686872 commit c13986d

12 files changed

Lines changed: 97 additions & 31 deletions

File tree

‎packages/react-art/src/ReactFiberConfigART.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ export function resolveUpdatePriority(): EventPriority {
363363
returncurrentUpdatePriority||DefaultEventPriority;
364364
}
365365

366+
exportfunctiontrackSchedulerEvent(): void{}
367+
366368
export functionresolveEventType(): null|string{
367369
returnnull;
368370
}

‎packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,19 @@ export function shouldAttemptEagerTransition(): boolean {
606606
returnfalse;
607607
}
608608

609+
letschedulerEvent: void|Event=undefined;
610+
exportfunctiontrackSchedulerEvent(): void{
611+
schedulerEvent=window.event;
612+
}
613+
609614
export functionresolveEventType(): null|string{
610615
constevent=window.event;
611-
returnevent ? event.type : null;
616+
returnevent&&event!==schedulerEvent? event.type : null;
612617
}
613618

614619
exportfunctionresolveEventTimeStamp(): number{
615620
constevent=window.event;
616-
returnevent ? event.timeStamp : -1.1;
621+
returnevent&&event!==schedulerEvent? event.timeStamp : -1.1;
617622
}
618623

619624
exportconstisPrimaryRenderer=true;

‎packages/react-native-renderer/src/ReactFiberConfigFabric.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ export function resolveUpdatePriority(): EventPriority {
372372
returnDefaultEventPriority;
373373
}
374374

375+
exportfunctiontrackSchedulerEvent(): void{}
376+
375377
export functionresolveEventType(): null|string{
376378
returnnull;
377379
}

‎packages/react-native-renderer/src/ReactFiberConfigNative.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ export function resolveUpdatePriority(): EventPriority {
288288
returnDefaultEventPriority;
289289
}
290290

291+
exportfunctiontrackSchedulerEvent(): void{}
292+
291293
export functionresolveEventType(): null|string{
292294
returnnull;
293295
}

‎packages/react-noop-renderer/src/createReactNoop.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
531531
returncurrentEventPriority;
532532
},
533533

534+
trackSchedulerEvent(): void{},
535+
534536
resolveEventType(): null|string{
535537
return null;
536538
},

‎packages/react-reconciler/src/ReactFiberPerformanceTrack.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export function logBlockingStart(
118118
updateTime: number,
119119
eventTime: number,
120120
eventType: null|string,
121+
eventIsRepeat: boolean,
121122
renderStartTime: number,
122123
): void{
123124
if(supportsUserTiming){
@@ -127,7 +128,7 @@ export function logBlockingStart(
127128
reusableLaneDevToolDetails.color='secondary-dark';
128129
reusableLaneOptions.start=eventTime;
129130
reusableLaneOptions.end=updateTime>0 ? updateTime : renderStartTime;
130-
performance.measure(eventType,reusableLaneOptions);
131+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
131132
}
132133
if(updateTime>0){
133134
// Log the time from when we called setState until we started rendering.
@@ -144,6 +145,7 @@ export function logTransitionStart(
144145
updateTime: number,
145146
eventTime: number,
146147
eventType: null|string,
148+
eventIsRepeat: boolean,
147149
renderStartTime: number,
148150
): void{
149151
if(supportsUserTiming){
@@ -158,7 +160,7 @@ export function logTransitionStart(
158160
: updateTime>0
159161
? updateTime
160162
: renderStartTime;
161-
performance.measure(eventType,reusableLaneOptions);
163+
performance.measure(eventIsRepeat ? '' : eventType,reusableLaneOptions);
162164
}
163165
if(startTime>0){
164166
// Log the time from when we started an async transition until we called setState or started rendering.

‎packages/react-reconciler/src/ReactFiberRootScheduler.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
disableSchedulerTimeoutInWorkLoop,
1919
enableProfilerTimer,
2020
enableProfilerNestedUpdatePhase,
21+
enableComponentPerformanceTrack,
2122
enableSiblingPrerendering,
2223
}from'shared/ReactFeatureFlags';
2324
import{
@@ -64,6 +65,7 @@ import {
6465
supportsMicrotasks,
6566
scheduleMicrotask,
6667
shouldAttemptEagerTransition,
68+
trackSchedulerEvent,
6769
}from'./ReactFiberConfig';
6870

6971
importReactSharedInternalsfrom'shared/ReactSharedInternals';
@@ -225,6 +227,12 @@ function flushSyncWorkAcrossRoots_impl(
225227
}
226228

227229
functionprocessRootScheduleInMicrotask(){
230+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
231+
// Track the currently executing event if there is one so we can ignore this
232+
// event when logging events.
233+
trackSchedulerEvent();
234+
}
235+
228236
// This function is always called inside a microtask. It should never be
229237
// called synchronously.
230238
didScheduleMicrotask=false;
@@ -428,6 +436,12 @@ function performWorkOnRootViaSchedulerTask(
428436
resetNestedUpdateFlag();
429437
}
430438

439+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
440+
// Track the currently executing event if there is one so we can ignore this
441+
// event when logging events.
442+
trackSchedulerEvent();
443+
}
444+
431445
// Flush any pending passive effects before deciding which lanes to work on,
432446
// in case they schedule additional work.
433447
constoriginalCallbackNode=root.callbackNode;

‎packages/react-reconciler/src/ReactFiberWorkLoop.js‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
setCurrentUpdatePriority,
9191
getCurrentUpdatePriority,
9292
resolveUpdatePriority,
93+
trackSchedulerEvent,
9394
}from'./ReactFiberConfig';
9495

9596
import{createWorkInProgress,resetWorkInProgress}from'./ReactFiber';
@@ -229,13 +230,17 @@ import {
229230
}from'./ReactFiberConcurrentUpdates';
230231

231232
import{
233+
blockingClampTime,
232234
blockingUpdateTime,
233235
blockingEventTime,
234236
blockingEventType,
237+
blockingEventIsRepeat,
238+
transitionClampTime,
235239
transitionStartTime,
236240
transitionUpdateTime,
237241
transitionEventTime,
238242
transitionEventType,
243+
transitionEventIsRepeat,
239244
clearBlockingTimers,
240245
clearTransitionTimers,
241246
clampBlockingTimers,
@@ -938,6 +943,9 @@ export function performWorkOnRoot(
938943
}
939944
break;
940945
}elseif(exitStatus===RootDidNotComplete){
946+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
947+
finalizeRender(lanes,now());
948+
}
941949
// The render unwound without completing the tree. This happens in special
942950
// cases where need to exit the current render without producing a
943951
// consistent tree or committing.
@@ -1130,6 +1138,9 @@ function finishConcurrentRender(
11301138
// This is a transition, so we should exit without committing a
11311139
// placeholder and without scheduling a timeout. Delay indefinitely
11321140
// until we receive more data.
1141+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
1142+
finalizeRender(lanes,now());
1143+
}
11331144
constdidAttemptEntireTree=
11341145
!workInProgressRootDidSkipSuspendedSiblings;
11351146
markRootSuspended(
@@ -1655,19 +1666,31 @@ function prepareFreshStack(root: FiberRoot, lanes: Lanes): Fiber {
16551666

16561667
if(includesSyncLane(lanes)||includesBlockingLane(lanes)){
16571668
logBlockingStart(
1658-
blockingUpdateTime,
1659-
blockingEventTime,
1669+
blockingUpdateTime>=0&&blockingUpdateTime<blockingClampTime
1670+
? blockingClampTime
1671+
: blockingUpdateTime,
1672+
blockingEventTime>=0&&blockingEventTime<blockingClampTime
1673+
? blockingClampTime
1674+
: blockingEventTime,
16601675
blockingEventType,
1676+
blockingEventIsRepeat,
16611677
renderStartTime,
16621678
);
16631679
clearBlockingTimers();
16641680
}
16651681
if(includesTransitionLane(lanes)){
16661682
logTransitionStart(
1667-
transitionStartTime,
1668-
transitionUpdateTime,
1669-
transitionEventTime,
1683+
transitionStartTime>=0&&transitionStartTime<transitionClampTime
1684+
? transitionClampTime
1685+
: transitionStartTime,
1686+
transitionUpdateTime>=0&&transitionUpdateTime<transitionClampTime
1687+
? transitionClampTime
1688+
: transitionUpdateTime,
1689+
transitionEventTime>=0&&transitionEventTime<transitionClampTime
1690+
? transitionClampTime
1691+
: transitionEventTime,
16701692
transitionEventType,
1693+
transitionEventIsRepeat,
16711694
renderStartTime,
16721695
);
16731696
clearTransitionTimers();
@@ -3139,6 +3162,11 @@ function commitRootImpl(
31393162
// with setTimeout
31403163
pendingPassiveTransitions=transitions;
31413164
scheduleCallback(NormalSchedulerPriority,()=>{
3165+
if(enableProfilerTimer&&enableComponentPerformanceTrack){
3166+
// Track the currently executing event if there is one so we can ignore this
3167+
// event when logging events.
3168+
trackSchedulerEvent();
3169+
}
31423170
flushPassiveEffects(true);
31433171
// This render triggered passive effects: release the root cache pool
31443172
// *after* passive effects fire to avoid freeing a cache pool that may

‎packages/react-reconciler/src/ReactProfilerTimer.js‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ export let componentEffectDuration: number = -0;
3636
exportletcomponentEffectStartTime: number=-1.1;
3737
exportletcomponentEffectEndTime: number=-1.1;
3838

39+
exportletblockingClampTime: number=-0;
3940
exportletblockingUpdateTime: number=-1.1;// First sync setState scheduled.
4041
exportletblockingEventTime: number=-1.1;// Event timeStamp of the first setState.
4142
export letblockingEventType: null|string=null;// Event type of the first setState.
43+
exportletblockingEventIsRepeat: boolean=false;
4244
// TODO: This should really be one per Transition lane.
45+
exportlettransitionClampTime: number=-0;
4346
exportlettransitionStartTime: number=-1.1;// First startTransition call before setState.
4447
exportlettransitionUpdateTime: number=-1.1;// First transition setState scheduled.
4548
exportlettransitionEventTime: number=-1.1;// Event timeStamp of the first transition.
4649
export lettransitionEventType: null|string=null;// Event type of the first transition.
50+
exportlettransitionEventIsRepeat: boolean=false;
4751

4852
exportfunctionstartUpdateTimerByLane(lane: Lane): void{
4953
if(!enableProfilerTimer||!enableComponentPerformanceTrack){
@@ -52,15 +56,25 @@ export function startUpdateTimerByLane(lane: Lane): void {
5256
if(isSyncLane(lane)||isBlockingLane(lane)){
5357
if(blockingUpdateTime<0){
5458
blockingUpdateTime=now();
55-
blockingEventTime=resolveEventTimeStamp();
56-
blockingEventType=resolveEventType();
59+
constnewEventTime=resolveEventTimeStamp();
60+
constnewEventType=resolveEventType();
61+
blockingEventIsRepeat=
62+
newEventTime===blockingEventTime&&
63+
newEventType===blockingEventType;
64+
blockingEventTime=newEventTime;
65+
blockingEventType=newEventType;
5766
}
5867
}elseif(isTransitionLane(lane)){
5968
if(transitionUpdateTime<0){
6069
transitionUpdateTime=now();
6170
if(transitionStartTime<0){
62-
transitionEventTime=resolveEventTimeStamp();
63-
transitionEventType=resolveEventType();
71+
constnewEventTime=resolveEventTimeStamp();
72+
constnewEventType=resolveEventType();
73+
transitionEventIsRepeat=
74+
newEventTime===transitionEventTime&&
75+
newEventType===transitionEventType;
76+
transitionEventTime=newEventTime;
77+
transitionEventType=newEventType;
6478
}
6579
}
6680
}
@@ -76,8 +90,13 @@ export function startAsyncTransitionTimer(): void {
7690
}
7791
if(transitionStartTime<0&&transitionUpdateTime<0){
7892
transitionStartTime=now();
79-
transitionEventTime=resolveEventTimeStamp();
80-
transitionEventType=resolveEventType();
93+
constnewEventTime=resolveEventTimeStamp();
94+
constnewEventType=resolveEventType();
95+
transitionEventIsRepeat=
96+
newEventTime===transitionEventTime&&
97+
newEventType===transitionEventType;
98+
transitionEventTime=newEventTime;
99+
transitionEventType=newEventType;
81100
}
82101
}
83102

@@ -115,12 +134,7 @@ export function clampBlockingTimers(finalTime: number): void {
115134
// If we had new updates come in while we were still rendering or committing, we don't want
116135
// those update times to create overlapping tracks in the performance timeline so we clamp
117136
// them to the end of the commit phase.
118-
if(blockingUpdateTime>=0&&blockingUpdateTime<finalTime){
119-
blockingUpdateTime=finalTime;
120-
}
121-
if(blockingEventTime>=0&&blockingEventTime<finalTime){
122-
blockingEventTime=finalTime;
123-
}
137+
blockingClampTime=finalTime;
124138
}
125139

126140
exportfunctionclampTransitionTimers(finalTime: number): void{
@@ -130,15 +144,7 @@ export function clampTransitionTimers(finalTime: number): void {
130144
// If we had new updates come in while we were still rendering or committing, we don't want
131145
// those update times to create overlapping tracks in the performance timeline so we clamp
132146
// them to the end of the commit phase.
133-
if(transitionStartTime>=0&&transitionStartTime<finalTime){
134-
transitionStartTime=finalTime;
135-
}
136-
if(transitionUpdateTime>=0&&transitionUpdateTime<finalTime){
137-
transitionUpdateTime=finalTime;
138-
}
139-
if(transitionEventTime>=0&&transitionEventTime<finalTime){
140-
transitionEventTime=finalTime;
141-
}
147+
transitionClampTime=finalTime;
142148
}
143149

144150
exportfunctionpushNestedEffectDurations(): number{

‎packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('ReactFiberHostContext', () => {
8383
}
8484
returnDefaultEventPriority;
8585
},
86+
trackSchedulerEvent: function(){},
8687
resolveEventType: function(){
8788
returnnull;
8889
},

0 commit comments

Comments
 (0)