@@ -71,6 +71,7 @@ import {
7171 DidCapture ,
7272 Snapshot ,
7373 MutationMask ,
74+ PerformedWork ,
7475 StaticMask ,
7576} from './ReactFiberFlags' ;
7677import invariant from 'shared/invariant' ;
@@ -155,7 +156,10 @@ import {
155156} from './ReactFiberLane' ;
156157import { resetChildFibers } from './ReactChildFiber.new' ;
157158import { createScopeInstance } from './ReactFiberScope.new' ;
158- import { transferActualDuration } from './ReactProfilerTimer.new' ;
159+ import {
160+ stopProfilerTimerIfRunning ,
161+ stopProfilerTimerIfRunningAndRecordDelta ,
162+ } from './ReactProfilerTimer.new' ;
159163
160164function markUpdate ( workInProgress : Fiber ) {
161165 // Tag the fiber with an update effect. This turns a Placement into
@@ -681,112 +685,99 @@ function cutOffTailIfNeeded(
681685 }
682686}
683687
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 ;
688695
689- let newChildLanes = NoLanes ;
690- let subtreeFlags = NoFlags ;
696+ // TODO (effects) Document
697+ parent . treeBaseDuration = 0 ;
698+ }
699+ }
700+ }
701+ }
691702
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+ }
706708
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 ) ;
709717
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 ;
718721
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+ }
721726 }
722-
723- completedWork . actualDuration = actualDuration ;
724- completedWork . treeBaseDuration = treeBaseDuration ;
725727 } 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 ) ;
735731
736- child = child . sibling ;
732+ parent . treeBaseDuration += completedWork . treeBaseDuration ;
733+ }
737734 }
738735 }
736+ }
737+ }
739738
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 ;
754743
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+ ) ;
761754
762- treeBaseDuration += child . treeBaseDuration ;
763- child = child . sibling ;
764- }
755+ subtreeFlags |= child . subtreeFlags ;
756+ subtreeFlags |= child . flags ;
765757
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+ ) ;
774767
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 ;
781774
782- child = child . sibling ;
783- }
775+ child = child . sibling ;
784776 }
785-
786- completedWork . subtreeFlags |= subtreeFlags ;
787777 }
788778
789779 completedWork . childLanes = newChildLanes ;
780+ completedWork . subtreeFlags |= subtreeFlags ;
790781}
791782
792783function completeWork (
@@ -1036,12 +1027,6 @@ function completeWork(
10361027 // Something suspended. Re-render with the fallback children.
10371028 workInProgress . lanes = renderLanes ;
10381029 // Do not reset the effect list.
1039- if (
1040- enableProfilerTimer &&
1041- ( workInProgress . mode & ProfileMode ) !== NoMode
1042- ) {
1043- transferActualDuration ( workInProgress ) ;
1044- }
10451030 return workInProgress ;
10461031 }
10471032
0 commit comments