This commit is contained in:
锌小子 2025-05-05 20:38:29 +00:00 committed by GitHub
commit 75397a9623
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 4 deletions

View File

@ -683,6 +683,16 @@ describe('KeepAlive', () => {
await nextTick()
assertHookCalls(one, [2, 2, 1, 1, 1])
assertHookCalls(two, [1, 1, 1, 1, 0])
includeRef.value = ''
await nextTick()
assertHookCalls(one, [2, 2, 1, 1, 1])
assertHookCalls(two, [1, 1, 1, 1, 1])
viewRef.value = 'two'
await nextTick()
assertHookCalls(one, [2, 2, 1, 1, 2])
assertHookCalls(two, [2, 2, 1, 1, 1])
})
test('on exclude change', async () => {
@ -702,6 +712,16 @@ describe('KeepAlive', () => {
await nextTick()
assertHookCalls(one, [2, 2, 1, 1, 1])
assertHookCalls(two, [1, 1, 1, 1, 0])
excludeRef.value = ''
await nextTick()
assertHookCalls(one, [2, 2, 1, 1, 1])
assertHookCalls(two, [1, 1, 1, 1, 0])
excludeRef.value = 'two'
await nextTick()
assertHookCalls(one, [2, 2, 1, 1, 1])
assertHookCalls(two, [1, 1, 1, 1, 1])
})
test('on include change + view switch', async () => {

View File

@ -226,8 +226,8 @@ const KeepAliveImpl: ComponentOptions = {
watch(
() => [props.include, props.exclude],
([include, exclude]) => {
include && pruneCache(name => matches(include, name))
exclude && pruneCache(name => !matches(exclude, name))
include != null && pruneCache(name => matches(include, name))
exclude != null && pruneCache(name => !matches(exclude, name))
},
// prune post-render after `current` has been updated
{ flush: 'post', deep: true },
@ -312,8 +312,8 @@ const KeepAliveImpl: ComponentOptions = {
const { include, exclude, max } = props
if (
(include && (!name || !matches(include, name))) ||
(exclude && name && matches(exclude, name))
(include != null && (!name || !matches(include, name))) ||
(exclude != null && name && matches(exclude, name))
) {
// #11717
vnode.shapeFlag &= ~ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE