@@ -67,10 +67,15 @@ import {
6767import {
6868 Ref ,
6969 Update ,
70+ Callback ,
71+ Passive ,
72+ Deletion ,
7073 NoFlags ,
7174 DidCapture ,
7275 Snapshot ,
7376 MutationMask ,
77+ LayoutMask ,
78+ PassiveMask ,
7479 StaticMask ,
7580} from './ReactFiberFlags' ;
7681import invariant from 'shared/invariant' ;
@@ -787,6 +792,8 @@ function bubbleProperties(completedWork: Fiber) {
787792 }
788793
789794 completedWork . childLanes = newChildLanes ;
795+
796+ return didBailout ;
790797}
791798
792799function completeWork (
@@ -804,7 +811,6 @@ function completeWork(
804811 case ForwardRef :
805812 case Fragment :
806813 case Mode :
807- case Profiler :
808814 case ContextConsumer :
809815 case MemoComponent :
810816 bubbleProperties ( workInProgress ) ;
@@ -966,6 +972,53 @@ function completeWork(
966972 bubbleProperties ( workInProgress ) ;
967973 return null ;
968974 }
975+ case Profiler : {
976+ const didBailout = bubbleProperties ( workInProgress ) ;
977+ if ( ! didBailout ) {
978+ // Use subtreeFlags to determine which commit callbacks should fire.
979+ // TODO: Move this logic to the commit phase, since we already check if
980+ // a fiber's subtree contains effects. Refactor the commit phase's
981+ // depth-first traversal so that we can put work tag-specific logic
982+ // before or after committing a subtree's effects.
983+ const OnRenderFlag = Update ;
984+ const OnCommitFlag = Callback ;
985+ const OnPostCommitFlag = Passive ;
986+ const subtreeFlags = workInProgress . subtreeFlags ;
987+ const flags = workInProgress . flags ;
988+ let newFlags = flags ;
989+
990+ // Call onRender any time this fiber or its subtree are worked on, even
991+ // if there are no effects
992+ newFlags |= OnRenderFlag ;
993+
994+ // Call onCommit only if the subtree contains layout work, or if it
995+ // contains deletions, since those might result in unmount work, which
996+ // we include in the same measure.
997+ // TODO: Can optimize by using a static flag to track whether a tree
998+ // contains layout effects, like we do for passive effects.
999+ if (
1000+ ( flags & ( LayoutMask | Deletion ) ) !== NoFlags ||
1001+ ( subtreeFlags & ( LayoutMask | Deletion ) ) !== NoFlags
1002+ ) {
1003+ newFlags |= OnCommitFlag ;
1004+ }
1005+
1006+ // Call onPostCommit only if the subtree contains passive work.
1007+ // Don't have to check for deletions, because Deletion is already
1008+ // a passive flag.
1009+ if (
1010+ ( flags & PassiveMask ) !== NoFlags ||
1011+ ( subtreeFlags & PassiveMask ) !== NoFlags
1012+ ) {
1013+ newFlags |= OnPostCommitFlag ;
1014+ }
1015+ workInProgress . flags = newFlags ;
1016+ } else {
1017+ // This fiber and its subtree bailed out, so don't fire any callbacks.
1018+ }
1019+
1020+ return null ;
1021+ }
9691022 case SuspenseComponent : {
9701023 popSuspenseContext ( workInProgress ) ;
9711024 const nextState : null | SuspenseState = workInProgress . memoizedState ;
0 commit comments