mirror of https://github.com/vuejs/core.git
fix(runtime-vapor): properly mount component when using setInsertionState (#13041)
This commit is contained in:
parent
504fa10de3
commit
b9dc8658cb
|
@ -2,6 +2,7 @@ import {
|
|||
type Ref,
|
||||
inject,
|
||||
nextTick,
|
||||
onMounted,
|
||||
onUpdated,
|
||||
provide,
|
||||
ref,
|
||||
|
@ -13,6 +14,7 @@ import {
|
|||
createIf,
|
||||
createTextNode,
|
||||
renderEffect,
|
||||
setInsertionState,
|
||||
template,
|
||||
} from '../src'
|
||||
import { makeRender } from './_utils'
|
||||
|
@ -266,6 +268,29 @@ describe('component', () => {
|
|||
expect(spy).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('properly mount child component when using setInsertionState', async () => {
|
||||
const spy = vi.fn()
|
||||
|
||||
const { component: Comp } = define({
|
||||
setup() {
|
||||
onMounted(spy)
|
||||
return template('<h1>hi</h1>')()
|
||||
},
|
||||
})
|
||||
|
||||
const { host } = define({
|
||||
setup() {
|
||||
const n2 = template('<div></div>', true)()
|
||||
setInsertionState(n2 as any)
|
||||
createComponent(Comp)
|
||||
return n2
|
||||
},
|
||||
}).render()
|
||||
|
||||
expect(host.innerHTML).toBe('<div><h1>hi</h1></div>')
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('unmount component', async () => {
|
||||
const { host, app, instance } = define(() => {
|
||||
const count = ref(0)
|
||||
|
|
|
@ -276,7 +276,7 @@ export function createComponent(
|
|||
onScopeDispose(() => unmountComponent(instance), true)
|
||||
|
||||
if (!isHydrating && _insertionParent) {
|
||||
insert(instance.block, _insertionParent, _insertionAnchor)
|
||||
mountComponent(instance, _insertionParent, _insertionAnchor)
|
||||
}
|
||||
|
||||
return instance
|
||||
|
|
Loading…
Reference in New Issue