@@ -34,6 +34,8 @@ import {
3434 TREE_OPERATION_ADD ,
3535 TREE_OPERATION_REMOVE ,
3636 TREE_OPERATION_REORDER_CHILDREN ,
37+ SUSPENSE_TREE_OPERATION_ADD ,
38+ SUSPENSE_TREE_OPERATION_REMOVE ,
3739 UNKNOWN_SUSPENDERS_NONE ,
3840} from '../../constants' ;
3941import { decorateMany , forceUpdate , restoreMany } from './utils' ;
@@ -411,6 +413,13 @@ export function attach(
411413 pushOperation ( 0 ) ; // StrictMode supported?
412414 pushOperation ( hasOwnerMetadata ? 1 : 0 ) ;
413415 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 ) ;
414423 } else {
415424 const type = getElementType ( internalInstance ) ;
416425 const { displayName, key} = getData ( internalInstance ) ;
@@ -449,7 +458,12 @@ export function attach(
449458 }
450459
451460 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+ }
453467 idToInternalInstanceMap . delete ( id ) ;
454468 }
455469
@@ -519,6 +533,8 @@ export function attach(
519533 // All unmounts are batched in a single message.
520534 // [TREE_OPERATION_REMOVE, removedIDLength, ...ids]
521535 (numUnmountIDs > 0 ? 2 + numUnmountIDs : 0 ) +
536+ // [SUSPENSE_TREE_OPERATION_REMOVE, 1, pendingUnmountedRootID]
537+ ( pendingUnmountedRootID === null ? 0 : 3 ) +
522538 // Mount operations
523539 pendingOperations . length ,
524540 ) ;
@@ -555,6 +571,10 @@ export function attach(
555571 if ( pendingUnmountedRootID !== null ) {
556572 operations [ i ] = pendingUnmountedRootID ;
557573 i ++ ;
574+
575+ operations [ i ++ ] = SUSPENSE_TREE_OPERATION_REMOVE ;
576+ operations [ i ++ ] = 1 ;
577+ operations [ i ++ ] = pendingUnmountedRootID ;
558578 }
559579 }
560580
0 commit comments