@@ -23,6 +23,7 @@ import {
2323 enableProfilerTimer ,
2424 enableProfilerCommitHooks ,
2525 enableProfilerNestedUpdatePhase ,
26+ enableProfilerNestedUpdateScheduledHook ,
2627 enableSchedulerTracing ,
2728 warnAboutUnmockedScheduler ,
2829 deferRenderPhaseUpdateToNextBatch ,
@@ -112,6 +113,7 @@ import {
112113 OffscreenComponent ,
113114 LegacyHiddenComponent ,
114115 ScopeComponent ,
116+ Profiler ,
115117} from './ReactWorkTags' ;
116118import { LegacyRoot } from './ReactRootTags' ;
117119import {
@@ -329,6 +331,10 @@ let hasUncaughtError = false;
329331let firstUncaughtError = null;
330332let legacyErrorBoundariesThatAlreadyFailed: Set< mixed > | null = null;
331333
334+ // Only used when enableProfilerNestedUpdateScheduledHook is true;
335+ // to track which root is currently committing layout effects.
336+ let rootCommittingMutationOrLayoutEffects: FiberRoot | null = null;
337+
332338let rootDoesHavePassiveEffects: boolean = false;
333339let rootWithPendingPassiveEffects: FiberRoot | null = null;
334340let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority;
@@ -533,6 +539,30 @@ export function scheduleUpdateOnFiber(
533539 // Mark that the root has a pending update.
534540 markRootUpdated(root, lane, eventTime);
535541
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+
536566 if ( root === workInProgressRoot ) {
537567 // Received an update to a tree that's in the middle of rendering. Mark
538568 // that there was an interleaved update work on this root. Unless the
@@ -2047,6 +2077,12 @@ function commitRootImpl(root, renderPriorityLevel) {
20472077 recordCommitTime ( ) ;
20482078 }
20492079
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+
20502086 // The next phase is the mutation phase, where we mutate the host tree.
20512087 nextEffect = firstEffect ;
20522088 do {
@@ -2112,6 +2148,10 @@ function commitRootImpl(root, renderPriorityLevel) {
21122148
21132149 nextEffect = null ;
21142150
2151+ if ( enableProfilerTimer && enableProfilerNestedUpdateScheduledHook ) {
2152+ rootCommittingMutationOrLayoutEffects = null ;
2153+ }
2154+
21152155 // Tell Scheduler to yield at the end of the frame, so the browser has an
21162156 // opportunity to paint.
21172157 requestPaint ( ) ;
0 commit comments