fix(keep-alive): invoke initial activated hook for async components

revert #5459
fix #5095
fix #5651
This commit is contained in:
Evan You
2022-05-12 11:29:26 +08:00
parent 9d815d28ad
commit 20ed16f68c
3 changed files with 22 additions and 12 deletions

View File

@@ -802,7 +802,7 @@ describe('api: defineAsyncComponent', () => {
expect(vnodeHooks.onVnodeUnmounted).toHaveBeenCalledTimes(1)
})
test('with keepalive', async () => {
test('with KeepAlive', async () => {
const spy = jest.fn()
let resolve: (comp: Component) => void
@@ -813,9 +813,12 @@ describe('api: defineAsyncComponent', () => {
})
)
const Bar = defineAsyncComponent(() => Promise.resolve(() => 'Bar'))
const toggle = ref(true)
const root = nodeOps.createElement('div')
const app = createApp({
render: () => h(KeepAlive, [h(Foo)])
render: () => h(KeepAlive, [toggle.value ? h(Foo) : h(Bar)])
})
app.mount(root)
@@ -826,13 +829,16 @@ describe('api: defineAsyncComponent', () => {
onActivated(() => {
spy()
})
return () => 'resolved'
return () => 'Foo'
}
})
await timeout()
expect(serializeInner(root)).toBe('resolved')
expect(serializeInner(root)).toBe('Foo')
expect(spy).toBeCalledTimes(1)
})
toggle.value = false
await timeout()
expect(serializeInner(root)).toBe('Bar')
})
})