@@ -432,7 +432,7 @@ function createSuspenseBoundary(
432
432
m : move ,
433
433
um : unmount ,
434
434
n : next ,
435
- o : { parentNode, remove }
435
+ o : { nextSibling , parentNode, remove }
436
436
} = rendererInternals
437
437
438
438
// if set `suspensible: true`, set the current suspense as a dep of parent suspense
@@ -494,28 +494,42 @@ function createSuspenseBoundary(
494
494
if ( suspense . isHydrating ) {
495
495
suspense . isHydrating = false
496
496
} else if ( ! resume ) {
497
+ const anchorCands : RendererNode [ ] = [ ]
498
+ if ( activeBranch ) {
499
+ for ( let node = next ( activeBranch ) ; node ; node = nextSibling ( node ) ) {
500
+ anchorCands . push ( node )
501
+ }
502
+ }
503
+
504
+ // this is initial anchor on mount
505
+ const { anchor : initialAnchor } = suspense
506
+
497
507
const delayEnter =
498
508
activeBranch &&
499
509
pendingBranch ! . transition &&
500
510
pendingBranch ! . transition . mode === 'out-in'
511
+
501
512
if ( delayEnter ) {
502
513
activeBranch ! . transition ! . afterLeave = ( ) => {
503
514
if ( pendingId === suspense . pendingId ) {
515
+ const anchor =
516
+ anchorCands . find ( x => parentNode ( x ) === container ) ||
517
+ initialAnchor
504
518
move ( pendingBranch ! , container , anchor , MoveType . ENTER )
505
519
}
506
520
}
507
521
}
508
- // this is initial anchor on mount
509
- let { anchor } = suspense
522
+
510
523
// unmount current active tree
511
524
if ( activeBranch ) {
512
525
// if the fallback tree was mounted, it may have been moved
513
526
// as part of a parent suspense. get the latest anchor for insertion
514
- anchor = next ( activeBranch )
515
527
unmount ( activeBranch , parentComponent , suspense , true )
516
528
}
517
529
if ( ! delayEnter ) {
518
530
// move content from off-dom container to actual container
531
+ const anchor =
532
+ anchorCands . find ( x => parentNode ( x ) === container ) || initialAnchor
519
533
move ( pendingBranch ! , container , anchor , MoveType . ENTER )
520
534
}
521
535
}
0 commit comments