Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): pruneCacheEntry rectify the judgment logic (fix #7355) #7510

Merged
merged 2 commits into from Feb 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/runtime-core/src/components/KeepAlive.ts
Expand Up @@ -13,7 +13,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