@@ -1293,11 +1293,11 @@ export function attach(
1293
1293
'Expected the root instance to already exist when applying filters' ,
1294
1294
) ;
1295
1295
}
1296
- currentRootID = rootInstance . id ;
1296
+ currentRoot = rootInstance ;
1297
1297
unmountInstanceRecursively ( rootInstance ) ;
1298
1298
rootToFiberInstanceMap . delete ( root ) ;
1299
1299
flushPendingEvents ( root ) ;
1300
- currentRootID = - 1 ;
1300
+ currentRoot = ( null : any ) ;
1301
1301
} ) ;
1302
1302
1303
1303
applyComponentFilters ( componentFilters ) ;
@@ -1323,11 +1323,11 @@ export function attach(
1323
1323
mightBeOnTrackedPath = true ;
1324
1324
}
1325
1325
1326
- currentRootID = newRoot . id ;
1327
- setRootPseudoKey ( currentRootID , root . current ) ;
1326
+ currentRoot = newRoot ;
1327
+ setRootPseudoKey ( currentRoot . id , root . current ) ;
1328
1328
mountFiberRecursively ( root . current , false ) ;
1329
1329
flushPendingEvents ( root ) ;
1330
- currentRootID = - 1 ;
1330
+ currentRoot = ( null : any ) ;
1331
1331
} ) ;
1332
1332
1333
1333
// Also re-evaluate all error and warning counts given the new filters.
@@ -1528,7 +1528,7 @@ export function attach(
1528
1528
}
1529
1529
1530
1530
// When a mount or update is in progress, this value tracks the root that is being operated on.
1531
- let currentRootID : number = - 1 ;
1531
+ let currentRoot : FiberInstance = ( null : any ) ;
1532
1532
1533
1533
// Returns a FiberInstance if one has already been generated for the Fiber or null if one has not been generated.
1534
1534
// Use this method while e.g. logging to avoid over-retaining Fibers.
@@ -1885,7 +1885,12 @@ export function attach(
1885
1885
3 + pendingOperations . length ,
1886
1886
) ;
1887
1887
operations [ 0 ] = rendererID ;
1888
- operations [ 1 ] = currentRootID ;
1888
+ if ( currentRoot === null ) {
1889
+ // TODO: This is not always safe so this field is probably not needed.
1890
+ operations [ 1 ] = - 1 ;
1891
+ } else {
1892
+ operations [ 1 ] = currentRoot . id ;
1893
+ }
1889
1894
operations [ 2 ] = 0 ; // String table size
1890
1895
for ( let j = 0 ; j < pendingOperations . length ; j ++ ) {
1891
1896
operations [ 3 + j ] = pendingOperations [ j ] ;
@@ -2038,7 +2043,12 @@ export function attach(
2038
2043
// Which in turn enables fiber props, states, and hooks to be inspected.
2039
2044
let i = 0 ;
2040
2045
operations [ i ++ ] = rendererID ;
2041
- operations [ i ++ ] = currentRootID ;
2046
+ if ( currentRoot === null ) {
2047
+ // TODO: This is not always safe so this field is probably not needed.
2048
+ operations [ i ++ ] = - 1 ;
2049
+ } else {
2050
+ operations [ i ++ ] = currentRoot . id ;
2051
+ }
2042
2052
2043
2053
// Now fill in the string table.
2044
2054
// [stringTableLength, str1Length, ...str1, str2Length, ...str2, ...]
@@ -2881,6 +2891,25 @@ export function attach(
2881
2891
}
2882
2892
}
2883
2893
}
2894
+
2895
+ // If this Fiber was in the set of memoizedUpdaters we need to record
2896
+ // it to be included in the description of the commit.
2897
+ const fiberRoot : FiberRoot = currentRoot . data . stateNode ;
2898
+ const updaters = fiberRoot . memoizedUpdaters ;
2899
+ if (
2900
+ updaters != null &&
2901
+ ( updaters . has ( fiber ) ||
2902
+ // We check the alternate here because we're matching identity and
2903
+ // prevFiber might be same as fiber.
2904
+ ( fiber . alternate !== null && updaters . has ( fiber . alternate ) ) )
2905
+ ) {
2906
+ const metadata =
2907
+ ( ( currentCommitProfilingMetadata : any ) : CommitProfilingData ) ;
2908
+ if ( metadata . updaters === null ) {
2909
+ metadata . updaters = [ ] ;
2910
+ }
2911
+ metadata . updaters . push ( instanceToSerializedElement ( fiberInstance ) ) ;
2912
+ }
2884
2913
}
2885
2914
}
2886
2915
@@ -3568,8 +3597,8 @@ export function attach(
3568
3597
if ( alternate ) {
3569
3598
fiberToFiberInstanceMap . set ( alternate , newRoot ) ;
3570
3599
}
3571
- currentRootID = newRoot . id ;
3572
- setRootPseudoKey ( currentRootID , root . current ) ;
3600
+ currentRoot = newRoot ;
3601
+ setRootPseudoKey ( currentRoot . id , root . current ) ;
3573
3602
3574
3603
// Handle multi-renderer edge-case where only some v16 renderers support profiling.
3575
3604
if ( isProfiling && rootSupportsProfiling ( root ) ) {
@@ -3581,35 +3610,20 @@ export function attach(
3581
3610
commitTime : getCurrentTime ( ) - profilingStartTime ,
3582
3611
maxActualDuration : 0 ,
3583
3612
priorityLevel : null ,
3584
- updaters : getUpdatersList ( root ) ,
3613
+ updaters : null ,
3585
3614
effectDuration : null ,
3586
3615
passiveEffectDuration : null ,
3587
3616
} ;
3588
3617
}
3589
3618
3590
3619
mountFiberRecursively ( root . current , false ) ;
3620
+
3591
3621
flushPendingEvents ( root ) ;
3592
- currentRootID = - 1 ;
3622
+ currentRoot = ( null : any ) ;
3593
3623
} ) ;
3594
3624
}
3595
3625
}
3596
3626
3597
- function getUpdatersList ( root : any ) : Array < SerializedElement > | null {
3598
- const updaters = root . memoizedUpdaters ;
3599
- if ( updaters == null ) {
3600
- return null ;
3601
- }
3602
- const result = [ ] ;
3603
- // eslint-disable-next-line no-for-of-loops/no-for-of-loops
3604
- for ( const updater of updaters ) {
3605
- const inst = getFiberInstanceUnsafe ( updater ) ;
3606
- if ( inst !== null ) {
3607
- result . push ( instanceToSerializedElement ( inst ) ) ;
3608
- }
3609
- }
3610
- return result ;
3611
- }
3612
-
3613
3627
function handleCommitFiberUnmount ( fiber : any ) {
3614
3628
// This Hook is no longer used. After having shipped DevTools everywhere it is
3615
3629
// safe to stop calling it from Fiber.
@@ -3646,11 +3660,10 @@ export function attach(
3646
3660
if ( alternate ) {
3647
3661
fiberToFiberInstanceMap . set ( alternate , rootInstance ) ;
3648
3662
}
3649
- currentRootID = rootInstance . id ;
3650
3663
} else {
3651
- currentRootID = rootInstance . id ;
3652
3664
prevFiber = rootInstance . data ;
3653
3665
}
3666
+ currentRoot = rootInstance ;
3654
3667
3655
3668
// Before the traversals, remember to start tracking
3656
3669
// our path in case we have selection to restore.
@@ -3675,9 +3688,7 @@ export function attach(
3675
3688
maxActualDuration : 0 ,
3676
3689
priorityLevel :
3677
3690
priorityLevel == null ? null : formatPriorityLevel ( priorityLevel ) ,
3678
-
3679
- updaters : getUpdatersList ( root ) ,
3680
-
3691
+ updaters : null ,
3681
3692
// Initialize to null; if new enough React version is running,
3682
3693
// these values will be read during separate handlePostCommitFiberRoot() call.
3683
3694
effectDuration : null ,
@@ -3699,28 +3710,28 @@ export function attach(
3699
3710
current . memoizedState . isDehydrated !== true ;
3700
3711
if ( ! wasMounted && isMounted ) {
3701
3712
// Mount a new root.
3702
- setRootPseudoKey ( currentRootID , current ) ;
3713
+ setRootPseudoKey ( currentRoot . id , current ) ;
3703
3714
mountFiberRecursively ( current , false ) ;
3704
3715
} else if ( wasMounted && isMounted ) {
3705
3716
// Update an existing root.
3706
3717
updateFiberRecursively ( rootInstance , current , prevFiber , false ) ;
3707
3718
} else if ( wasMounted && ! isMounted ) {
3708
3719
// Unmount an existing root.
3709
3720
unmountInstanceRecursively ( rootInstance ) ;
3710
- removeRootPseudoKey ( currentRootID ) ;
3721
+ removeRootPseudoKey ( currentRoot . id ) ;
3711
3722
rootToFiberInstanceMap . delete ( root ) ;
3712
3723
}
3713
3724
} else {
3714
3725
// Mount a new root.
3715
- setRootPseudoKey ( currentRootID , current ) ;
3726
+ setRootPseudoKey ( currentRoot . id , current ) ;
3716
3727
mountFiberRecursively ( current , false ) ;
3717
3728
}
3718
3729
3719
3730
if ( isProfiling && isProfilingSupported ) {
3720
3731
if ( ! shouldBailoutWithPendingOperations ( ) ) {
3721
3732
const commitProfilingMetadata =
3722
3733
( ( rootToCommitProfilingMetadataMap : any ) : CommitProfilingMetadataMap ) . get (
3723
- currentRootID ,
3734
+ currentRoot . id ,
3724
3735
) ;
3725
3736
3726
3737
if ( commitProfilingMetadata != null ) {
@@ -3729,7 +3740,7 @@ export function attach(
3729
3740
) ;
3730
3741
} else {
3731
3742
( ( rootToCommitProfilingMetadataMap : any ) : CommitProfilingMetadataMap ) . set (
3732
- currentRootID ,
3743
+ currentRoot . id ,
3733
3744
[ ( ( currentCommitProfilingMetadata : any ) : CommitProfilingData ) ] ,
3734
3745
) ;
3735
3746
}
@@ -3743,7 +3754,7 @@ export function attach(
3743
3754
hook . emit ( 'traceUpdates' , traceUpdatesForNodes ) ;
3744
3755
}
3745
3756
3746
- currentRootID = - 1 ;
3757
+ currentRoot = ( null : any ) ;
3747
3758
}
3748
3759
3749
3760
function getResourceInstance ( fiber : Fiber ) : HostInstance | null {
0 commit comments