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

+4-3
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
function pruneCacheEntry(key: CacheKey) {
195196
const cached = cache.get(key) as VNode
196-
if (!current || cached.type !== current.type) {
197+
if (!current || !isSameVNodeType(cached, current)) {
197198
unmount(cached)
198199
} else if (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
const vnode = 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)