@@ -2363,7 +2363,7 @@ export function attach(
2363
2363
}
2364
2364
2365
2365
if ( isProfilingSupported ) {
2366
- recordProfilingDurations ( fiberInstance ) ;
2366
+ recordProfilingDurations ( fiberInstance , null ) ;
2367
2367
}
2368
2368
return fiberInstance ;
2369
2369
}
@@ -2929,21 +2929,22 @@ export function attach(
2929
2929
removeChild ( instance , null ) ;
2930
2930
}
2931
2931
2932
- function recordProfilingDurations ( fiberInstance : FiberInstance ) {
2932
+ function recordProfilingDurations (
2933
+ fiberInstance : FiberInstance ,
2934
+ prevFiber : null | Fiber ,
2935
+ ) {
2933
2936
const id = fiberInstance . id ;
2934
2937
const fiber = fiberInstance . data ;
2935
2938
const { actualDuration , treeBaseDuration } = fiber ;
2936
2939
2937
2940
fiberInstance . treeBaseDuration = treeBaseDuration || 0 ;
2938
2941
2939
2942
if ( isProfiling ) {
2940
- const { alternate} = fiber ;
2941
-
2942
2943
// It's important to update treeBaseDuration even if the current Fiber did not render,
2943
2944
// because it's possible that one of its descendants did.
2944
2945
if (
2945
- alternate == null ||
2946
- treeBaseDuration !== alternate . treeBaseDuration
2946
+ prevFiber == null ||
2947
+ treeBaseDuration !== prevFiber . treeBaseDuration
2947
2948
) {
2948
2949
// Tree base duration updates are included in the operations typed array.
2949
2950
// So we have to convert them from milliseconds to microseconds so we can send them as ints.
@@ -2955,7 +2956,7 @@ export function attach(
2955
2956
pushOperation ( convertedTreeBaseDuration ) ;
2956
2957
}
2957
2958
2958
- if ( alternate == null || didFiberRender ( alternate , fiber ) ) {
2959
+ if ( prevFiber == null || didFiberRender ( prevFiber , fiber ) ) {
2959
2960
if ( actualDuration != null ) {
2960
2961
// The actual duration reported by React includes time spent working on children.
2961
2962
// This is useful information, but it's also useful to be able to exclude child durations.
@@ -2983,7 +2984,7 @@ export function attach(
2983
2984
) ;
2984
2985
2985
2986
if ( recordChangeDescriptions ) {
2986
- const changeDescription = getChangeDescription ( alternate , fiber ) ;
2987
+ const changeDescription = getChangeDescription ( prevFiber , fiber ) ;
2987
2988
if ( changeDescription !== null ) {
2988
2989
if ( metadata . changeDescriptions !== null ) {
2989
2990
metadata . changeDescriptions . set ( id , changeDescription ) ;
@@ -3306,8 +3307,6 @@ export function attach(
3306
3307
// Register the new alternate in case it's not already in.
3307
3308
fiberToFiberInstanceMap . set ( nextChild , fiberInstance ) ;
3308
3309
3309
- // Update the Fiber so we that we always keep the current Fiber on the data.
3310
- fiberInstance . data = nextChild ;
3311
3310
moveChild ( fiberInstance , previousSiblingOfExistingInstance ) ;
3312
3311
3313
3312
if (
@@ -3447,6 +3446,8 @@ export function attach(
3447
3446
const stashedPrevious = previouslyReconciledSibling ;
3448
3447
const stashedRemaining = remainingReconcilingChildren ;
3449
3448
if ( fiberInstance !== null ) {
3449
+ // Update the Fiber so we that we always keep the current Fiber on the data.
3450
+ fiberInstance . data = nextFiber ;
3450
3451
if (
3451
3452
mostRecentlyInspectedElement !== null &&
3452
3453
mostRecentlyInspectedElement . id === fiberInstance . id &&
@@ -3602,7 +3603,7 @@ export function attach(
3602
3603
const isProfilingSupported =
3603
3604
nextFiber . hasOwnProperty ( 'treeBaseDuration' ) ;
3604
3605
if ( isProfilingSupported ) {
3605
- recordProfilingDurations ( fiberInstance ) ;
3606
+ recordProfilingDurations ( fiberInstance , prevFiber ) ;
3606
3607
}
3607
3608
}
3608
3609
if ( shouldResetChildren ) {
@@ -3673,11 +3674,11 @@ export function attach(
3673
3674
// If we have not been profiling, then we can just walk the tree and build up its current state as-is.
3674
3675
hook . getFiberRoots ( rendererID ) . forEach ( root => {
3675
3676
const current = root . current ;
3676
- const alternate = current . alternate ;
3677
3677
const newRoot = createFiberInstance ( current ) ;
3678
3678
rootToFiberInstanceMap . set ( root , newRoot ) ;
3679
3679
idToDevToolsInstanceMap . set ( newRoot . id , newRoot ) ;
3680
3680
fiberToFiberInstanceMap . set ( current , newRoot ) ;
3681
+ const alternate = current . alternate ;
3681
3682
if ( alternate ) {
3682
3683
fiberToFiberInstanceMap . set ( alternate , newRoot ) ;
3683
3684
}
@@ -3747,20 +3748,22 @@ export function attach(
3747
3748
priorityLevel : void | number ,
3748
3749
) {
3749
3750
const current = root . current ;
3750
- const alternate = current . alternate ;
3751
3751
3752
+ let prevFiber : null | Fiber = null ;
3752
3753
let rootInstance = rootToFiberInstanceMap . get ( root ) ;
3753
3754
if ( ! rootInstance ) {
3754
3755
rootInstance = createFiberInstance ( current ) ;
3755
3756
rootToFiberInstanceMap . set ( root , rootInstance ) ;
3756
3757
idToDevToolsInstanceMap . set ( rootInstance . id , rootInstance ) ;
3757
3758
fiberToFiberInstanceMap . set ( current , rootInstance ) ;
3759
+ const alternate = current . alternate ;
3758
3760
if ( alternate ) {
3759
3761
fiberToFiberInstanceMap . set ( alternate , rootInstance ) ;
3760
3762
}
3761
3763
currentRootID = rootInstance . id ;
3762
3764
} else {
3763
3765
currentRootID = rootInstance . id ;
3766
+ prevFiber = rootInstance . data ;
3764
3767
}
3765
3768
3766
3769
// Before the traversals, remember to start tracking
@@ -3796,13 +3799,13 @@ export function attach(
3796
3799
} ;
3797
3800
}
3798
3801
3799
- if ( alternate ) {
3802
+ if ( prevFiber !== null ) {
3800
3803
// TODO: relying on this seems a bit fishy.
3801
3804
const wasMounted =
3802
- alternate . memoizedState != null &&
3803
- alternate . memoizedState . element != null &&
3805
+ prevFiber . memoizedState != null &&
3806
+ prevFiber . memoizedState . element != null &&
3804
3807
// A dehydrated root is not considered mounted
3805
- alternate . memoizedState . isDehydrated !== true ;
3808
+ prevFiber . memoizedState . isDehydrated !== true ;
3806
3809
const isMounted =
3807
3810
current . memoizedState != null &&
3808
3811
current . memoizedState . element != null &&
@@ -3814,7 +3817,7 @@ export function attach(
3814
3817
mountFiberRecursively ( current , false ) ;
3815
3818
} else if ( wasMounted && isMounted ) {
3816
3819
// Update an existing root.
3817
- updateFiberRecursively ( rootInstance , current , alternate , false ) ;
3820
+ updateFiberRecursively ( rootInstance , current , prevFiber , false ) ;
3818
3821
} else if ( wasMounted && ! isMounted ) {
3819
3822
// Unmount an existing root.
3820
3823
unmountInstanceRecursively ( rootInstance ) ;
0 commit comments