fix(Transition): fix transition memory leak edge case (#12182)

close #12181
This commit is contained in:
edison 2024-11-15 10:40:26 +08:00 committed by GitHub
parent 4aeff318bd
commit 660132df6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 6 deletions

View File

@ -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 (
@ -208,7 +207,7 @@ const BaseTransitionImpl: ComponentOptions = {
!isSameVNodeType(innerChild, oldInnerChild) &&
recursiveGetSubtree(instance).type !== Comment
) {
const leavingHooks = resolveTransitionHooks(
let leavingHooks = resolveTransitionHooks(
oldInnerChild,
rawProps,
state,
@ -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) {
@ -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
enterHooks.delayedLeave = () => {
delayedLeave()
delete enterHooks.delayedLeave
oldInnerChild = undefined
}
}
} else {
oldInnerChild = undefined
}
} else if (oldInnerChild) {
oldInnerChild = undefined
}
return child