Skip to content

Commit 1fde49c

Browse files
authored
fix(runtime-core): fix keep-alive cache prune logic on vnodes with same type but different keys (#7510)
fix#7355
1 parent f19f803 commit 1fde49c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

‎packages/runtime-core/src/components/KeepAlive.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import{
1212
cloneVNode,
1313
isVNode,
1414
VNodeProps,
15-
invokeVNodeHook
15+
invokeVNodeHook,
16+
isSameVNodeType
1617
}from'../vnode'
1718
import{warn}from'../warning'
1819
import{
@@ -193,7 +194,7 @@ const KeepAliveImpl: ComponentOptions ={
193194

194195
functionpruneCacheEntry(key: CacheKey){
195196
constcached=cache.get(key)asVNode
196-
if(!current||cached.type!==current.type){
197+
if(!current||!isSameVNodeType(cached,current)){
197198
unmount(cached)
198199
}elseif(current){
199200
// current active instance should no longer be kept-alive.
@@ -230,7 +231,7 @@ const KeepAliveImpl: ComponentOptions ={
230231
cache.forEach(cached=>{
231232
const{ subTree, suspense }=instance
232233
constvnode=getInnerChild(subTree)
233-
if(cached.type===vnode.type){
234+
if(cached.type===vnode.type&&cached.key===vnode.key){
234235
// current instance will be unmounted as part of keep-alive's unmount
235236
resetShapeFlag(vnode)
236237
// but invoke its deactivated hook here

0 commit comments

Comments
(0)