@@ -29,6 +29,7 @@ import {
2929 deferPassiveEffectCleanupDuringUnmount ,
3030 enableSchedulerTracing ,
3131 enableProfilerTimer ,
32+ enableProfilerCommitHooks ,
3233 enableSuspenseServerRenderer ,
3334 enableDeprecatedFlareAPI ,
3435 enableFundamentalAPI ,
@@ -183,7 +184,11 @@ const callComponentWillUnmountWithTimer = function(current, instance) {
183184 startPhaseTimer ( current , 'componentWillUnmount' ) ;
184185 instance . props = current . memoizedProps ;
185186 instance . state = current . memoizedState ;
186- if ( enableProfilerTimer && current . mode & ProfileMode ) {
187+ if (
188+ enableProfilerTimer &&
189+ enableProfilerCommitHooks &&
190+ current . mode & ProfileMode
191+ ) {
187192 try {
188193 startLayoutEffectTimer ( ) ;
189194 instance . componentWillUnmount ( ) ;
@@ -447,7 +452,11 @@ export function commitPassiveHookEffects(finishedWork: Fiber): void {
447452 // TODO (#17945) We should call all passive destroy functions (for all fibers)
448453 // before calling any create functions. The current approach only serializes
449454 // these for a single fiber.
450- if ( enableProfilerTimer && finishedWork . mode & ProfileMode ) {
455+ if (
456+ enableProfilerTimer &&
457+ enableProfilerCommitHooks &&
458+ finishedWork . mode & ProfileMode
459+ ) {
451460 try {
452461 startPassiveEffectTimer ( ) ;
453462 commitHookEffectListUnmount (
@@ -480,7 +489,7 @@ export function commitPassiveEffectDurations(
480489 finishedRoot : FiberRoot ,
481490 finishedWork : Fiber ,
482491) : void {
483- if ( enableProfilerTimer ) {
492+ if ( enableProfilerTimer && enableProfilerCommitHooks ) {
484493 // Only Profilers with work in their subtree will have an Update effect scheduled.
485494 if ( ( finishedWork . effectTag & Update ) !== NoEffect ) {
486495 switch ( finishedWork . tag ) {
@@ -546,7 +555,11 @@ function commitLifeCycles(
546555 // This is done to prevent sibling component effects from interfering with each other,
547556 // e.g. a destroy function in one component should never override a ref set
548557 // by a create function in another component during the same commit.
549- if ( enableProfilerTimer && finishedWork . mode & ProfileMode ) {
558+ if (
559+ enableProfilerTimer &&
560+ enableProfilerCommitHooks &&
561+ finishedWork . mode & ProfileMode
562+ ) {
550563 try {
551564 startLayoutEffectTimer ( ) ;
552565 commitHookEffectListMount ( HookLayout | HookHasEffect , finishedWork ) ;
@@ -597,7 +610,11 @@ function commitLifeCycles(
597610 }
598611 }
599612 }
600- if ( enableProfilerTimer && finishedWork . mode & ProfileMode ) {
613+ if (
614+ enableProfilerTimer &&
615+ enableProfilerCommitHooks &&
616+ finishedWork . mode & ProfileMode
617+ ) {
601618 try {
602619 startLayoutEffectTimer ( ) ;
603620 instance . componentDidMount ( ) ;
@@ -645,7 +662,11 @@ function commitLifeCycles(
645662 }
646663 }
647664 }
648- if ( enableProfilerTimer && finishedWork . mode & ProfileMode ) {
665+ if (
666+ enableProfilerTimer &&
667+ enableProfilerCommitHooks &&
668+ finishedWork . mode & ProfileMode
669+ ) {
649670 try {
650671 startLayoutEffectTimer ( ) ;
651672 instance . componentDidUpdate (
@@ -773,40 +794,42 @@ function commitLifeCycles(
773794 }
774795 }
775796
776- if ( typeof onCommit === 'function' ) {
777- if ( enableSchedulerTracing ) {
778- onCommit (
779- finishedWork . memoizedProps . id ,
780- current === null ? 'mount' : 'update' ,
781- effectDuration ,
782- commitTime ,
783- finishedRoot . memoizedInteractions ,
784- ) ;
785- } else {
786- onCommit (
787- finishedWork . memoizedProps . id ,
788- current === null ? 'mount' : 'update' ,
789- effectDuration ,
790- commitTime ,
791- ) ;
797+ if ( enableProfilerCommitHooks ) {
798+ if ( typeof onCommit === 'function' ) {
799+ if ( enableSchedulerTracing ) {
800+ onCommit (
801+ finishedWork . memoizedProps . id ,
802+ current === null ? 'mount' : 'update' ,
803+ effectDuration ,
804+ commitTime ,
805+ finishedRoot . memoizedInteractions ,
806+ ) ;
807+ } else {
808+ onCommit (
809+ finishedWork . memoizedProps . id ,
810+ current === null ? 'mount' : 'update' ,
811+ effectDuration ,
812+ commitTime ,
813+ ) ;
814+ }
792815 }
793- }
794816
795- // Schedule a passive effect for this Profiler to call onPostCommit hooks.
796- // This effect should be scheduled even if there is no onPostCommit callback for this Profiler,
797- // because the effect is also where times bubble to parent Profilers.
798- enqueuePendingPassiveProfilerEffect ( finishedWork ) ;
799-
800- // Propagate layout effect durations to the next nearest Profiler ancestor.
801- // Do not reset these values until the next render so DevTools has a chance to read them first.
802- let parentFiber = finishedWork . return ;
803- while ( parentFiber !== null ) {
804- if ( parentFiber . tag === Profiler ) {
805- const parentStateNode = parentFiber . stateNode ;
806- parentStateNode . effectDuration += effectDuration ;
807- break ;
817+ // Schedule a passive effect for this Profiler to call onPostCommit hooks.
818+ // This effect should be scheduled even if there is no onPostCommit callback for this Profiler,
819+ // because the effect is also where times bubble to parent Profilers.
820+ enqueuePendingPassiveProfilerEffect ( finishedWork ) ;
821+
822+ // Propagate layout effect durations to the next nearest Profiler ancestor.
823+ // Do not reset these values until the next render so DevTools has a chance to read them first.
824+ let parentFiber = finishedWork . return ;
825+ while ( parentFiber !== null ) {
826+ if ( parentFiber . tag === Profiler ) {
827+ const parentStateNode = parentFiber . stateNode ;
828+ parentStateNode . effectDuration += effectDuration ;
829+ break ;
830+ }
831+ parentFiber = parentFiber . return ;
808832 }
809- parentFiber = parentFiber . return ;
810833 }
811834 }
812835 return ;
@@ -958,7 +981,11 @@ function commitUnmount(
958981 if ( ( tag & HookPassive ) !== NoHookEffect ) {
959982 enqueuePendingPassiveHookEffectUnmount ( current , effect ) ;
960983 } else {
961- if ( enableProfilerTimer && current . mode & ProfileMode ) {
984+ if (
985+ enableProfilerTimer &&
986+ enableProfilerCommitHooks &&
987+ current . mode & ProfileMode
988+ ) {
962989 startLayoutEffectTimer ( ) ;
963990 safelyCallDestroy ( current , destroy ) ;
964991 recordLayoutEffectDuration ( current ) ;
@@ -991,7 +1018,11 @@ function commitUnmount(
9911018 do {
9921019 const { destroy, tag} = effect ;
9931020 if ( destroy !== undefined ) {
994- if ( enableProfilerTimer && current . mode & ProfileMode ) {
1021+ if (
1022+ enableProfilerTimer &&
1023+ enableProfilerCommitHooks &&
1024+ current . mode & ProfileMode
1025+ ) {
9951026 if ( ( tag & HookPassive ) !== NoHookEffect ) {
9961027 safelyCallDestroy ( current , destroy ) ;
9971028 } else {
@@ -1543,7 +1574,11 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
15431574 // This prevents sibling component effects from interfering with each other,
15441575 // e.g. a destroy function in one component should never override a ref set
15451576 // by a create function in another component during the same commit.
1546- if ( enableProfilerTimer && finishedWork . mode & ProfileMode ) {
1577+ if (
1578+ enableProfilerTimer &&
1579+ enableProfilerCommitHooks &&
1580+ finishedWork . mode & ProfileMode
1581+ ) {
15471582 try {
15481583 startLayoutEffectTimer ( ) ;
15491584 commitHookEffectListUnmount (
@@ -1598,7 +1633,11 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
15981633 // This prevents sibling component effects from interfering with each other,
15991634 // e.g. a destroy function in one component should never override a ref set
16001635 // by a create function in another component during the same commit.
1601- if ( enableProfilerTimer && finishedWork . mode & ProfileMode ) {
1636+ if (
1637+ enableProfilerTimer &&
1638+ enableProfilerCommitHooks &&
1639+ finishedWork . mode & ProfileMode
1640+ ) {
16021641 try {
16031642 startLayoutEffectTimer ( ) ;
16041643 commitHookEffectListUnmount ( HookLayout | HookHasEffect , finishedWork ) ;
0 commit comments