Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/corePublic

fix(KeepAlive): use resolved component name for async components in cache pruning#14212

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
edison1105 merged 1 commit intovuejs:mainfromhuangxiuqi:fix-14210
Dec 18, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletionspackages/runtime-core/__tests__/components/KeepAlive.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1173,4 +1173,53 @@ describe('KeepAlive', () => {
expect(deactivatedHome).toHaveBeenCalledTimes(0)
expect(unmountedHome).toHaveBeenCalledTimes(1)
})

test('should work with async component when update `include` props', async () => {
let resolve: (comp: Component) => void
const AsyncComp = defineAsyncComponent(
() =>
new Promise(r => {
resolve = r as any
}),
)

const toggle = ref(true)
const instanceRef = ref<any>(null)
const keepaliveInclude = ref(['Foo'])
const App = {
render: () => {
return h(KeepAlive, { include: keepaliveInclude.value }, () =>
toggle.value ? h(AsyncComp, { ref: instanceRef }) : null,
)
},
}

render(h(App), root)
// async component has not been resolved
expect(serializeInner(root)).toBe('<!---->')

resolve!({
name: 'Foo',
data: () => ({ count: 0 }),
render() {
return h('p', this.count)
},
})

await timeout()
// resolved
expect(serializeInner(root)).toBe('<p>0</p>')

// change state + toggle out + update `include` props
instanceRef.value.count++
toggle.value = false
keepaliveInclude.value = ['Foo']
await nextTick()
expect(serializeInner(root)).toBe('<!---->')

// toggle in, state should be maintained
toggle.value = true
await nextTick()
expect(serializeInner(root)).toBe('<p>1</p>')
})
})
8 changes: 7 additions & 1 deletionpackages/runtime-core/src/components/KeepAlive.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -202,7 +202,13 @@ const KeepAliveImpl: ComponentOptions = {

functionpruneCache(filter:(name:string)=>boolean){
cache.forEach((vnode,key)=>{
constname=getComponentName(vnode.typeasConcreteComponent)
// for async components, name check should be based in its loaded
// inner component if available
constname=getComponentName(
isAsyncWrapper(vnode)
?(vnode.typeasComponentOptions).__asyncResolved||{}
:(vnode.typeasConcreteComponent),
)
if(name&&!filter(name)){
pruneCacheEntry(key)
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp