Skip to content

Commit b9a3b5a

Browse files
committed
fix(runtime-core): close vuejs#8105
1 parent 597f9b8 commit b9a3b5a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/runtime-core/src/components/Suspense.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ function createSuspenseBoundary(
432432
m: move,
433433
um: unmount,
434434
n: next,
435-
o: { parentNode, remove }
435+
o: { nextSibling, parentNode, remove }
436436
} = rendererInternals
437437

438438
// if set `suspensible: true`, set the current suspense as a dep of parent suspense
@@ -494,28 +494,42 @@ function createSuspenseBoundary(
494494
if (suspense.isHydrating) {
495495
suspense.isHydrating = false
496496
} 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+
497507
const delayEnter =
498508
activeBranch &&
499509
pendingBranch!.transition &&
500510
pendingBranch!.transition.mode === 'out-in'
511+
501512
if (delayEnter) {
502513
activeBranch!.transition!.afterLeave = () => {
503514
if (pendingId === suspense.pendingId) {
515+
const anchor =
516+
anchorCands.find(x => parentNode(x) === container) ||
517+
initialAnchor
504518
move(pendingBranch!, container, anchor, MoveType.ENTER)
505519
}
506520
}
507521
}
508-
// this is initial anchor on mount
509-
let { anchor } = suspense
522+
510523
// unmount current active tree
511524
if (activeBranch) {
512525
// if the fallback tree was mounted, it may have been moved
513526
// as part of a parent suspense. get the latest anchor for insertion
514-
anchor = next(activeBranch)
515527
unmount(activeBranch, parentComponent, suspense, true)
516528
}
517529
if (!delayEnter) {
518530
// move content from off-dom container to actual container
531+
const anchor =
532+
anchorCands.find(x => parentNode(x) === container) || initialAnchor
519533
move(pendingBranch!, container, anchor, MoveType.ENTER)
520534
}
521535
}

0 commit comments

Comments
 (0)