fix(runtime-core): vnode hooks should not be called on async wrapper (#4349)
fix #4346
This commit is contained in:
@@ -744,4 +744,59 @@ describe('api: defineAsyncComponent', () => {
|
||||
expect(serializeInner(root)).toBe('<!---->')
|
||||
expect(fooRef.value).toBe(null)
|
||||
})
|
||||
|
||||
test('vnode hooks on async wrapper', async () => {
|
||||
let resolve: (comp: Component) => void
|
||||
const Foo = defineAsyncComponent(
|
||||
() =>
|
||||
new Promise(r => {
|
||||
resolve = r as any
|
||||
})
|
||||
)
|
||||
const updater = ref(0)
|
||||
|
||||
const vnodeHooks = {
|
||||
onVnodeBeforeMount: jest.fn(),
|
||||
onVnodeMounted: jest.fn(),
|
||||
onVnodeBeforeUpdate: jest.fn(),
|
||||
onVnodeUpdated: jest.fn(),
|
||||
onVnodeBeforeUnmount: jest.fn(),
|
||||
onVnodeUnmounted: jest.fn()
|
||||
}
|
||||
|
||||
const toggle = ref(true)
|
||||
|
||||
const root = nodeOps.createElement('div')
|
||||
createApp({
|
||||
render: () => (toggle.value ? [h(Foo, vnodeHooks), updater.value] : null)
|
||||
}).mount(root)
|
||||
|
||||
expect(serializeInner(root)).toBe('<!---->0')
|
||||
|
||||
resolve!({
|
||||
data() {
|
||||
return {
|
||||
id: 'foo'
|
||||
}
|
||||
},
|
||||
render: () => 'resolved'
|
||||
})
|
||||
|
||||
await timeout()
|
||||
expect(serializeInner(root)).toBe('resolved0')
|
||||
expect(vnodeHooks.onVnodeBeforeMount).toHaveBeenCalledTimes(1)
|
||||
expect(vnodeHooks.onVnodeMounted).toHaveBeenCalledTimes(1)
|
||||
|
||||
updater.value++
|
||||
await nextTick()
|
||||
expect(serializeInner(root)).toBe('resolved1')
|
||||
expect(vnodeHooks.onVnodeBeforeUpdate).toHaveBeenCalledTimes(1)
|
||||
expect(vnodeHooks.onVnodeUpdated).toHaveBeenCalledTimes(1)
|
||||
|
||||
toggle.value = false
|
||||
await nextTick()
|
||||
expect(serializeInner(root)).toBe('<!---->')
|
||||
expect(vnodeHooks.onVnodeBeforeUnmount).toHaveBeenCalledTimes(1)
|
||||
expect(vnodeHooks.onVnodeUnmounted).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user