fix(keep-alive): fix memory leak without breaking transition tests

This commit is contained in:
Evan You 2023-12-07 17:07:15 +08:00
parent 2632249925
commit e0747f40a8
2 changed files with 8 additions and 4 deletions

View File

@ -33,10 +33,15 @@ function matches(
}
function pruneCache(
keepAliveInstance: { cache: CacheEntryMap; keys: string[]; _vnode: VNode },
keepAliveInstance: {
cache: CacheEntryMap
keys: string[]
_vnode: VNode
$vnode: VNode
},
filter: Function
) {
const { cache, keys, _vnode } = keepAliveInstance
const { cache, keys, _vnode, $vnode } = keepAliveInstance
for (const key in cache) {
const entry = cache[key]
if (entry) {
@ -46,6 +51,7 @@ function pruneCache(
}
}
}
$vnode.componentOptions!.children = undefined
}
function pruneCacheEntry(

View File

@ -62,8 +62,6 @@ const componentVNodeHooks = {
vnode, // new parent vnode
options.children // new children
)
// #12187 unset children reference after use to avoid memory leak
options.children = undefined
},
insert(vnode: MountedComponentVNode) {