Skip to content

Commit

Permalink
fix(Transition): fix transition memory leak edge case (#12182)
Browse files Browse the repository at this point in the history
close #12181
  • Loading branch information
edison1105 authored Nov 15, 2024
1 parent 4aeff31 commit 660132d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/runtime-core/src/components/BaseTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ const BaseTransitionImpl: ComponentOptions = {
setTransitionHooks(innerChild, enterHooks)
}

const oldChild = instance.subTree
const oldInnerChild = oldChild && getInnerChild(oldChild)
let oldInnerChild = instance.subTree && getInnerChild(instance.subTree)

// handle mode
if (
Expand All @@ -208,7 +207,7 @@ const BaseTransitionImpl: ComponentOptions = {
!isSameVNodeType(innerChild, oldInnerChild) &&
recursiveGetSubtree(instance).type !== Comment
) {
const leavingHooks = resolveTransitionHooks(
let leavingHooks = resolveTransitionHooks(
oldInnerChild,
rawProps,
state,
Expand All @@ -228,6 +227,7 @@ const BaseTransitionImpl: ComponentOptions = {
instance.update()
}
delete leavingHooks.afterLeave
oldInnerChild = undefined
}
return emptyPlaceholder(child)
} else if (mode === 'in-out' && innerChild.type !== Comment) {
Expand All @@ -238,18 +238,27 @@ const BaseTransitionImpl: ComponentOptions = {
) => {
const leavingVNodesCache = getLeavingNodesForType(
state,
oldInnerChild,
oldInnerChild!,
)
leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild
leavingVNodesCache[String(oldInnerChild!.key)] = oldInnerChild!
// early removal callback
el[leaveCbKey] = () => {
earlyRemove()
el[leaveCbKey] = undefined
delete enterHooks.delayedLeave
oldInnerChild = undefined
}
enterHooks.delayedLeave = () => {
delayedLeave()
delete enterHooks.delayedLeave
oldInnerChild = undefined
}
enterHooks.delayedLeave = delayedLeave
}
} else {
oldInnerChild = undefined
}
} else if (oldInnerChild) {
oldInnerChild = undefined
}

return child
Expand Down

0 comments on commit 660132d

Please sign in to comment.