From: 李想 <32740073+GRPdream@users.noreply.github.com> Date: Wed, 1 Feb 2023 09:02:03 +0000 (+0800) Subject: fix(runtime-core): fix keep-alive cache prune logic on vnodes with same type but... X-Git-Tag: v3.2.46~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fde49c0f57cc50fedf91366a274c9759d1d9a39;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-core): fix keep-alive cache prune logic on vnodes with same type but different keys (#7510) fix #7355 --- diff --git a/packages/runtime-core/src/components/KeepAlive.ts b/packages/runtime-core/src/components/KeepAlive.ts index c3c2b63e45..d5813f90e0 100644 --- a/packages/runtime-core/src/components/KeepAlive.ts +++ b/packages/runtime-core/src/components/KeepAlive.ts @@ -12,7 +12,8 @@ import { cloneVNode, isVNode, VNodeProps, - invokeVNodeHook + invokeVNodeHook, + isSameVNodeType } from '../vnode' import { warn } from '../warning' import { @@ -193,7 +194,7 @@ const KeepAliveImpl: ComponentOptions = { function pruneCacheEntry(key: CacheKey) { const cached = cache.get(key) as VNode - if (!current || cached.type !== current.type) { + if (!current || !isSameVNodeType(cached, current)) { unmount(cached) } else if (current) { // current active instance should no longer be kept-alive. @@ -230,7 +231,7 @@ const KeepAliveImpl: ComponentOptions = { cache.forEach(cached => { const { subTree, suspense } = instance const vnode = getInnerChild(subTree) - if (cached.type === vnode.type) { + if (cached.type === vnode.type && cached.key === vnode.key) { // current instance will be unmounted as part of keep-alive's unmount resetShapeFlag(vnode) // but invoke its deactivated hook here