From ced1ed4e8a7ae176235a45787263a1b0ce0747c5 Mon Sep 17 00:00:00 2001 From: daiwei Date: Tue, 15 Oct 2024 21:22:33 +0800 Subject: [PATCH 1/3] fix(Transition): fix transition memory leak edge case --- packages/runtime-core/src/components/BaseTransition.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/src/components/BaseTransition.ts b/packages/runtime-core/src/components/BaseTransition.ts index 6ce06d28239..0cbd05b1a03 100644 --- a/packages/runtime-core/src/components/BaseTransition.ts +++ b/packages/runtime-core/src/components/BaseTransition.ts @@ -199,7 +199,7 @@ const BaseTransitionImpl: ComponentOptions = { } const oldChild = instance.subTree - const oldInnerChild = oldChild && getInnerChild(oldChild) + let oldInnerChild = oldChild && getInnerChild(oldChild) // handle mode if ( @@ -238,9 +238,9 @@ 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() @@ -250,6 +250,8 @@ const BaseTransitionImpl: ComponentOptions = { enterHooks.delayedLeave = delayedLeave } } + } else if (oldInnerChild) { + oldInnerChild = undefined } return child From ec2fcec0899056672ca9c32fc2ea0730fb3f0365 Mon Sep 17 00:00:00 2001 From: daiwei Date: Wed, 16 Oct 2024 09:51:18 +0800 Subject: [PATCH 2/3] chore: clean oldInnerChild --- .../runtime-core/src/components/BaseTransition.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/components/BaseTransition.ts b/packages/runtime-core/src/components/BaseTransition.ts index 0cbd05b1a03..d738e95fe56 100644 --- a/packages/runtime-core/src/components/BaseTransition.ts +++ b/packages/runtime-core/src/components/BaseTransition.ts @@ -208,7 +208,7 @@ const BaseTransitionImpl: ComponentOptions = { !isSameVNodeType(innerChild, oldInnerChild) && recursiveGetSubtree(instance).type !== Comment ) { - const leavingHooks = resolveTransitionHooks( + let leavingHooks = resolveTransitionHooks( oldInnerChild, rawProps, state, @@ -228,6 +228,7 @@ const BaseTransitionImpl: ComponentOptions = { instance.update() } delete leavingHooks.afterLeave + oldInnerChild = undefined } return emptyPlaceholder(child) } else if (mode === 'in-out' && innerChild.type !== Comment) { @@ -246,9 +247,16 @@ const BaseTransitionImpl: ComponentOptions = { 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 From ea53ad17ca9c474de5ef032a1be83ad37392ea49 Mon Sep 17 00:00:00 2001 From: daiwei Date: Wed, 16 Oct 2024 17:00:58 +0800 Subject: [PATCH 3/3] chore: minor tweak --- packages/runtime-core/src/components/BaseTransition.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/runtime-core/src/components/BaseTransition.ts b/packages/runtime-core/src/components/BaseTransition.ts index d738e95fe56..2b58bc3fc43 100644 --- a/packages/runtime-core/src/components/BaseTransition.ts +++ b/packages/runtime-core/src/components/BaseTransition.ts @@ -198,8 +198,7 @@ const BaseTransitionImpl: ComponentOptions = { setTransitionHooks(innerChild, enterHooks) } - const oldChild = instance.subTree - let oldInnerChild = oldChild && getInnerChild(oldChild) + let oldInnerChild = instance.subTree && getInnerChild(instance.subTree) // handle mode if (