Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9a9fad

Browse files
committed
fix(Transition): prevent unmounted block from being inserted after transition leave
1 parent 4d233ea commit f9a9fad

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎packages/runtime-vapor/src/block.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export function insert(
7979
parent: ParentNode & { $fc?: Node | null },
8080
anchor: Node | null | 0 = null, // 0 means prepend
8181
moveType: MoveType = MoveType.ENTER,
82+
parentComponent?: VaporComponentInstance,
8283
parentSuspense?: any, // TODO Suspense
8384
): void {
8485
anchor = anchor === 0 ? parent.$fc || _child(parent) : anchor
@@ -98,7 +99,15 @@ export function insert(
9899
action(
99100
block,
100101
(block as TransitionBlock).$transition as TransitionHooks,
101-
() => parent.insertBefore(block, anchor as Node),
102+
() => {
103+
// if the component is unmounted after leave finish, remove the block
104+
// to avoid retaining a detached node.
105+
if (moveType === MoveType.LEAVE && parentComponent!.isUnmounted) {
106+
block.remove()
107+
} else {
108+
parent.insertBefore(block, anchor as Node)
109+
}
110+
},
102111
parentSuspense,
103112
)
104113
} else {

‎packages/runtime-vapor/src/components/KeepAlive.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ export function deactivate(
359359
instance: VaporComponentInstance,
360360
container: ParentNode,
361361
): void {
362-
insert(instance.block, container, null, MoveType.LEAVE)
362+
insert(instance.block, container, null, MoveType.LEAVE, instance)
363363

364364
queuePostFlushCb(() => {
365365
if (instance.da) invokeArrayFns(instance.da)

0 commit comments

Comments
 (0)