@@ -23,6 +23,7 @@ import {
23
23
enableProfilerTimer ,
24
24
enableProfilerCommitHooks ,
25
25
enableProfilerNestedUpdatePhase ,
26
+ enableProfilerNestedUpdateScheduledHook ,
26
27
enableSchedulerTracing ,
27
28
warnAboutUnmockedScheduler ,
28
29
deferRenderPhaseUpdateToNextBatch ,
@@ -112,6 +113,7 @@ import {
112
113
OffscreenComponent ,
113
114
LegacyHiddenComponent ,
114
115
ScopeComponent ,
116
+ Profiler ,
115
117
} from './ReactWorkTags' ;
116
118
import { LegacyRoot } from './ReactRootTags' ;
117
119
import {
@@ -329,6 +331,10 @@ let hasUncaughtError = false;
329
331
let firstUncaughtError = null;
330
332
let legacyErrorBoundariesThatAlreadyFailed: Set< mixed > | null = null;
331
333
334
+ // Only used when enableProfilerNestedUpdateScheduledHook is true;
335
+ // to track which root is currently committing layout effects.
336
+ let rootCommittingMutationOrLayoutEffects: FiberRoot | null = null;
337
+
332
338
let rootDoesHavePassiveEffects: boolean = false;
333
339
let rootWithPendingPassiveEffects: FiberRoot | null = null;
334
340
let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority;
@@ -533,6 +539,30 @@ export function scheduleUpdateOnFiber(
533
539
// Mark that the root has a pending update.
534
540
markRootUpdated(root, lane, eventTime);
535
541
542
+ if (enableProfilerTimer && enableProfilerNestedUpdateScheduledHook ) {
543
+ if (
544
+ executionContext === CommitContext &&
545
+ root === rootCommittingMutationOrLayoutEffects
546
+ ) {
547
+ if ( fiber . mode & ProfileMode ) {
548
+ let current = fiber ;
549
+ while ( current !== null ) {
550
+ if ( current . tag === Profiler ) {
551
+ const { onNestedUpdateScheduled} = current . memoizedProps ;
552
+ if ( typeof onNestedUpdateScheduled === 'function' ) {
553
+ if ( enableSchedulerTracing ) {
554
+ onNestedUpdateScheduled ( root . memoizedInteractions ) ;
555
+ } else {
556
+ onNestedUpdateScheduled ( ) ;
557
+ }
558
+ }
559
+ }
560
+ current = current . return ;
561
+ }
562
+ }
563
+ }
564
+ }
565
+
536
566
if ( root === workInProgressRoot ) {
537
567
// Received an update to a tree that's in the middle of rendering. Mark
538
568
// that there was an interleaved update work on this root. Unless the
@@ -2047,6 +2077,12 @@ function commitRootImpl(root, renderPriorityLevel) {
2047
2077
recordCommitTime ( ) ;
2048
2078
}
2049
2079
2080
+ if ( enableProfilerTimer && enableProfilerNestedUpdateScheduledHook ) {
2081
+ // Track the root here, rather than in commitLayoutEffects(), because of ref setters.
2082
+ // Updates scheduled during ref detachment should also be flagged.
2083
+ rootCommittingMutationOrLayoutEffects = root ;
2084
+ }
2085
+
2050
2086
// The next phase is the mutation phase, where we mutate the host tree.
2051
2087
nextEffect = firstEffect ;
2052
2088
do {
@@ -2112,6 +2148,10 @@ function commitRootImpl(root, renderPriorityLevel) {
2112
2148
2113
2149
nextEffect = null ;
2114
2150
2151
+ if ( enableProfilerTimer && enableProfilerNestedUpdateScheduledHook ) {
2152
+ rootCommittingMutationOrLayoutEffects = null ;
2153
+ }
2154
+
2115
2155
// Tell Scheduler to yield at the end of the frame, so the browser has an
2116
2156
// opportunity to paint.
2117
2157
requestPaint ( ) ;
0 commit comments