Skip to content

Commit

Permalink
fix(runtime-core): fix keep-alive cache prune logic on vnodes with sa…
Browse files Browse the repository at this point in the history
…me type but different keys (vuejs#7510)

fix vuejs#7355
  • Loading branch information
GRPdream authored and IAmSSH committed Apr 29, 2023
1 parent b59aadb commit 5d6e62a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/runtime-core/src/components/KeepAlive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
cloneVNode,
isVNode,
VNodeProps,
invokeVNodeHook
invokeVNodeHook,
isSameVNodeType
} from '../vnode'
import { warn } from '../warning'
import {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5d6e62a

Please sign in to comment.