@@ -34,6 +34,8 @@ import {
34
34
TREE_OPERATION_ADD ,
35
35
TREE_OPERATION_REMOVE ,
36
36
TREE_OPERATION_REORDER_CHILDREN ,
37
+ SUSPENSE_TREE_OPERATION_ADD ,
38
+ SUSPENSE_TREE_OPERATION_REMOVE ,
37
39
UNKNOWN_SUSPENDERS_NONE ,
38
40
} from '../../constants' ;
39
41
import { decorateMany , forceUpdate , restoreMany } from './utils' ;
@@ -411,6 +413,13 @@ export function attach(
411
413
pushOperation ( 0 ) ; // StrictMode supported?
412
414
pushOperation ( hasOwnerMetadata ? 1 : 0 ) ;
413
415
pushOperation ( supportsTogglingSuspense ? 1 : 0 ) ;
416
+
417
+ pushOperation ( SUSPENSE_TREE_OPERATION_ADD ) ;
418
+ pushOperation ( id ) ;
419
+ pushOperation ( parentID ) ;
420
+ pushOperation ( getStringID ( null ) ) ; // name
421
+ // TODO: Measure rect of root
422
+ pushOperation ( - 1 ) ;
414
423
} else {
415
424
const type = getElementType ( internalInstance ) ;
416
425
const { displayName, key} = getData ( internalInstance ) ;
@@ -449,7 +458,12 @@ export function attach(
449
458
}
450
459
451
460
function recordUnmount ( internalInstance : InternalInstance , id : number ) {
452
- pendingUnmountedIDs . push ( id ) ;
461
+ const isRoot = parentIDStack . length === 0 ;
462
+ if ( isRoot ) {
463
+ pendingUnmountedRootID = id ;
464
+ } else {
465
+ pendingUnmountedIDs . push ( id ) ;
466
+ }
453
467
idToInternalInstanceMap . delete ( id ) ;
454
468
}
455
469
@@ -519,6 +533,8 @@ export function attach(
519
533
// All unmounts are batched in a single message.
520
534
// [TREE_OPERATION_REMOVE, removedIDLength, ...ids]
521
535
(numUnmountIDs > 0 ? 2 + numUnmountIDs : 0 ) +
536
+ // [SUSPENSE_TREE_OPERATION_REMOVE, 1, pendingUnmountedRootID]
537
+ ( pendingUnmountedRootID === null ? 0 : 3 ) +
522
538
// Mount operations
523
539
pendingOperations . length ,
524
540
) ;
@@ -555,6 +571,10 @@ export function attach(
555
571
if ( pendingUnmountedRootID !== null ) {
556
572
operations [ i ] = pendingUnmountedRootID ;
557
573
i ++ ;
574
+
575
+ operations [ i ++ ] = SUSPENSE_TREE_OPERATION_REMOVE ;
576
+ operations [ i ++ ] = 1 ;
577
+ operations [ i ++ ] = pendingUnmountedRootID ;
558
578
}
559
579
}
560
580
0 commit comments