@@ -71,6 +71,7 @@ import {
71
71
DidCapture ,
72
72
Snapshot ,
73
73
MutationMask ,
74
+ PerformedWork ,
74
75
StaticMask ,
75
76
} from './ReactFiberFlags' ;
76
77
import invariant from 'shared/invariant' ;
@@ -155,7 +156,10 @@ import {
155
156
} from './ReactFiberLane' ;
156
157
import { resetChildFibers } from './ReactChildFiber.new' ;
157
158
import { createScopeInstance } from './ReactFiberScope.new' ;
158
- import { transferActualDuration } from './ReactProfilerTimer.new' ;
159
+ import {
160
+ stopProfilerTimerIfRunning ,
161
+ stopProfilerTimerIfRunningAndRecordDelta ,
162
+ } from './ReactProfilerTimer.new' ;
159
163
160
164
function markUpdate ( workInProgress : Fiber ) {
161
165
// Tag the fiber with an update effect. This turns a Placement into
@@ -681,112 +685,99 @@ function cutOffTailIfNeeded(
681
685
}
682
686
}
683
687
684
- function bubbleProperties ( completedWork : Fiber ) {
685
- const didBailout =
686
- completedWork . alternate !== null &&
687
- completedWork . alternate . child === completedWork . child ;
688
+ export function bubbleProfilerDurationsAfterError ( erroredWork : Fiber ) : void {
689
+ if ( enableProfilerTimer ) {
690
+ if ( ( erroredWork . mode & ProfileMode ) !== NoMode ) {
691
+ const parent = erroredWork . return ;
692
+ if ( parent !== null ) {
693
+ // TODO (effects) Document
694
+ parent . actualDuration += erroredWork . actualDuration ;
688
695
689
- let newChildLanes = NoLanes ;
690
- let subtreeFlags = NoFlags ;
696
+ // TODO (effects) Document
697
+ parent . treeBaseDuration = 0 ;
698
+ }
699
+ }
700
+ }
701
+ }
691
702
692
- if ( ! didBailout ) {
693
- // Bubble up the earliest expiration time.
694
- if ( enableProfilerTimer && ( completedWork . mode & ProfileMode ) !== NoMode ) {
695
- // In profiling mode, resetChildExpirationTime is also used to reset
696
- // profiler durations.
697
- let actualDuration = completedWork . actualDuration ;
698
- let treeBaseDuration = ( ( completedWork . selfBaseDuration : any ) : number ) ;
699
-
700
- let child = completedWork . child ;
701
- while ( child !== null ) {
702
- newChildLanes = mergeLanes (
703
- newChildLanes ,
704
- mergeLanes ( child . lanes , child . childLanes ) ,
705
- ) ;
703
+ // TODO (effects) Temorary method; replace with bubblePropertiesToParent
704
+ function bubbleProperties ( completedWork : Fiber ) : void {
705
+ bubblePropertiesFromChildren ( completedWork ) ;
706
+ bubblePropertiesToParent ( completedWork ) ;
707
+ }
706
708
707
- subtreeFlags |= child . subtreeFlags ;
708
- subtreeFlags |= child . flags ;
709
+ function bubblePropertiesToParent ( completedWork : Fiber ) : void {
710
+ const parent = completedWork . return ;
711
+ if ( parent !== null ) {
712
+ const didBailout = ( completeWork . flags & PerformedWork ) !== NoFlags ;
713
+ if ( ! didBailout ) {
714
+ if ( enableProfilerTimer ) {
715
+ if ( ( completedWork . mode & ProfileMode ) !== NoMode ) {
716
+ stopProfilerTimerIfRunningAndRecordDelta ( completedWork , true ) ;
709
717
710
- // When a fiber is cloned, its actualDuration is reset to 0. This value will
711
- // only be updated if work is done on the fiber (i.e. it doesn't bailout).
712
- // When work is done, it should bubble to the parent's actualDuration. If
713
- // the fiber has not been cloned though, (meaning no work was done), then
714
- // this value will reflect the amount of time spent working on a previous
715
- // render. In that case it should not bubble. We determine whether it was
716
- // cloned by comparing the child pointer.
717
- actualDuration += child . actualDuration ;
718
+ // At this point child base durations have already bubbled up to treeBaseDuration.
719
+ // Add our own base duration before bubbling further to the parent Fiber.
720
+ completedWork . treeBaseDuration += completedWork . selfBaseDuration ;
718
721
719
- treeBaseDuration += child . treeBaseDuration ;
720
- child = child . sibling ;
722
+ // Bubble base durations to the parent.
723
+ parent . actualDuration += completedWork . actualDuration ;
724
+ parent . treeBaseDuration += completedWork . treeBaseDuration ;
725
+ }
721
726
}
722
-
723
- completedWork . actualDuration = actualDuration ;
724
- completedWork . treeBaseDuration = treeBaseDuration ;
725
727
} else {
726
- let child = completedWork . child ;
727
- while ( child !== null ) {
728
- newChildLanes = mergeLanes (
729
- newChildLanes ,
730
- mergeLanes ( child . lanes , child . childLanes ) ,
731
- ) ;
732
-
733
- subtreeFlags |= child . subtreeFlags ;
734
- subtreeFlags |= child . flags ;
728
+ if ( enableProfilerTimer ) {
729
+ if ( ( completedWork . mode & ProfileMode ) !== NoMode ) {
730
+ stopProfilerTimerIfRunning ( completedWork ) ;
735
731
736
- child = child . sibling ;
732
+ parent . treeBaseDuration += completedWork . treeBaseDuration ;
733
+ }
737
734
}
738
735
}
736
+ }
737
+ }
739
738
740
- completedWork . subtreeFlags |= subtreeFlags ;
741
- } else {
742
- // Bubble up the earliest expiration time.
743
- if ( enableProfilerTimer && ( completedWork . mode & ProfileMode ) !== NoMode ) {
744
- // In profiling mode, resetChildExpirationTime is also used to reset
745
- // profiler durations.
746
- let treeBaseDuration = ( ( completedWork . selfBaseDuration : any ) : number ) ;
747
-
748
- let child = completedWork . child ;
749
- while ( child !== null ) {
750
- newChildLanes = mergeLanes (
751
- newChildLanes ,
752
- mergeLanes ( child . lanes , child . childLanes ) ,
753
- ) ;
739
+ // TODO (effects) Move everything in this method into bubblePropertiesToParent
740
+ function bubblePropertiesFromChildren ( completedWork : Fiber ) : void {
741
+ let newChildLanes = NoLanes ;
742
+ let subtreeFlags = NoFlags ;
754
743
755
- // "Static" flags share the lifetime of the fiber/hook they belong to,
756
- // so we should bubble those up even during a bailout. All the other
757
- // flags have a lifetime only of a single render + commit, so we should
758
- // ignore them.
759
- subtreeFlags |= child . subtreeFlags & StaticMask ;
760
- subtreeFlags |= child . flags & StaticMask ;
744
+ const didBailout =
745
+ completedWork . alternate !== null &&
746
+ completedWork . alternate . child === completedWork . child ;
747
+ if ( ! didBailout ) {
748
+ let child = completedWork . child ;
749
+ while ( child !== null ) {
750
+ newChildLanes = mergeLanes (
751
+ newChildLanes ,
752
+ mergeLanes ( child . lanes , child . childLanes ) ,
753
+ ) ;
761
754
762
- treeBaseDuration += child . treeBaseDuration ;
763
- child = child . sibling ;
764
- }
755
+ subtreeFlags |= child . subtreeFlags ;
756
+ subtreeFlags |= child . flags ;
765
757
766
- completedWork . treeBaseDuration = treeBaseDuration ;
767
- } else {
768
- let child = completedWork . child ;
769
- while ( child !== null ) {
770
- newChildLanes = mergeLanes (
771
- newChildLanes ,
772
- mergeLanes ( child . lanes , child . childLanes ) ,
773
- ) ;
758
+ child = child . sibling ;
759
+ }
760
+ } else {
761
+ let child = completedWork . child ;
762
+ while ( child !== null ) {
763
+ newChildLanes = mergeLanes (
764
+ newChildLanes ,
765
+ mergeLanes ( child . lanes , child . childLanes ) ,
766
+ ) ;
774
767
775
- // "Static" flags share the lifetime of the fiber/hook they belong to,
776
- // so we should bubble those up even during a bailout. All the other
777
- // flags have a lifetime only of a single render + commit, so we should
778
- // ignore them.
779
- subtreeFlags |= child . subtreeFlags & StaticMask ;
780
- subtreeFlags |= child . flags & StaticMask ;
768
+ // "Static" flags share the lifetime of the fiber/hook they belong to,
769
+ // so we should bubble those up even during a bailout. All the other
770
+ // flags have a lifetime only of a single render + commit, so we should
771
+ // ignore them.
772
+ subtreeFlags |= child . subtreeFlags & StaticMask ;
773
+ subtreeFlags |= child . flags & StaticMask ;
781
774
782
- child = child . sibling ;
783
- }
775
+ child = child . sibling ;
784
776
}
785
-
786
- completedWork . subtreeFlags |= subtreeFlags ;
787
777
}
788
778
789
779
completedWork . childLanes = newChildLanes ;
780
+ completedWork . subtreeFlags |= subtreeFlags ;
790
781
}
791
782
792
783
function completeWork (
@@ -1036,12 +1027,6 @@ function completeWork(
1036
1027
// Something suspended. Re-render with the fallback children.
1037
1028
workInProgress . lanes = renderLanes ;
1038
1029
// Do not reset the effect list.
1039
- if (
1040
- enableProfilerTimer &&
1041
- ( workInProgress . mode & ProfileMode ) !== NoMode
1042
- ) {
1043
- transferActualDuration ( workInProgress ) ;
1044
- }
1045
1030
return workInProgress ;
1046
1031
}
1047
1032
0 commit comments