mirror of https://github.com/vuejs/core.git
fix(runtime-core): fix keep-alive cache prune logic on vnodes with same type but different keys (#7510)
fix #7355
This commit is contained in:
parent
f19f803ea8
commit
1fde49c0f5
|
@ -12,7 +12,8 @@ import {
|
||||||
cloneVNode,
|
cloneVNode,
|
||||||
isVNode,
|
isVNode,
|
||||||
VNodeProps,
|
VNodeProps,
|
||||||
invokeVNodeHook
|
invokeVNodeHook,
|
||||||
|
isSameVNodeType
|
||||||
} from '../vnode'
|
} from '../vnode'
|
||||||
import { warn } from '../warning'
|
import { warn } from '../warning'
|
||||||
import {
|
import {
|
||||||
|
@ -193,7 +194,7 @@ const KeepAliveImpl: ComponentOptions = {
|
||||||
|
|
||||||
function pruneCacheEntry(key: CacheKey) {
|
function pruneCacheEntry(key: CacheKey) {
|
||||||
const cached = cache.get(key) as VNode
|
const cached = cache.get(key) as VNode
|
||||||
if (!current || cached.type !== current.type) {
|
if (!current || !isSameVNodeType(cached, current)) {
|
||||||
unmount(cached)
|
unmount(cached)
|
||||||
} else if (current) {
|
} else if (current) {
|
||||||
// current active instance should no longer be kept-alive.
|
// current active instance should no longer be kept-alive.
|
||||||
|
@ -230,7 +231,7 @@ const KeepAliveImpl: ComponentOptions = {
|
||||||
cache.forEach(cached => {
|
cache.forEach(cached => {
|
||||||
const { subTree, suspense } = instance
|
const { subTree, suspense } = instance
|
||||||
const vnode = getInnerChild(subTree)
|
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
|
// current instance will be unmounted as part of keep-alive's unmount
|
||||||
resetShapeFlag(vnode)
|
resetShapeFlag(vnode)
|
||||||
// but invoke its deactivated hook here
|
// but invoke its deactivated hook here
|
||||||
|
|
Loading…
Reference in New Issue