From 64af9ffbf0277245278c8e926e86e80c014ce517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=83=B3?= <32740073+GRPdream@users.noreply.github.com> Date: Thu, 12 Jan 2023 11:16:11 +0800 Subject: [PATCH 1/2] fix(runtime-core): pruneCacheEntry rectify the judgment logic (fix #7355) keep-alive component status abnormal when cache items more than its max, after debugging, I found that its judge 2 VNode is same logic is wrong(as cached.type !== current.type). --- packages/runtime-core/src/components/KeepAlive.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/components/KeepAlive.ts b/packages/runtime-core/src/components/KeepAlive.ts index 554b9f2451c..cd556d686bd 100644 --- a/packages/runtime-core/src/components/KeepAlive.ts +++ b/packages/runtime-core/src/components/KeepAlive.ts @@ -13,7 +13,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. From 7231c29104d735f45ff159cada0a27a229d12e30 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 1 Feb 2023 04:00:54 -0500 Subject: [PATCH 2/2] Update KeepAlive.ts --- packages/runtime-core/src/components/KeepAlive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime-core/src/components/KeepAlive.ts b/packages/runtime-core/src/components/KeepAlive.ts index cd556d686bd..d884f323e76 100644 --- a/packages/runtime-core/src/components/KeepAlive.ts +++ b/packages/runtime-core/src/components/KeepAlive.ts @@ -231,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