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,
|
type Ref,
|
||||||
inject,
|
inject,
|
||||||
nextTick,
|
nextTick,
|
||||||
|
onMounted,
|
||||||
onUpdated,
|
onUpdated,
|
||||||
provide,
|
provide,
|
||||||
ref,
|
ref,
|
||||||
|
@ -13,6 +14,7 @@ import {
|
||||||
createIf,
|
createIf,
|
||||||
createTextNode,
|
createTextNode,
|
||||||
renderEffect,
|
renderEffect,
|
||||||
|
setInsertionState,
|
||||||
template,
|
template,
|
||||||
} from '../src'
|
} from '../src'
|
||||||
import { makeRender } from './_utils'
|
import { makeRender } from './_utils'
|
||||||
|
@ -266,6 +268,29 @@ describe('component', () => {
|
||||||
expect(spy).toHaveBeenCalledTimes(2)
|
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 () => {
|
it('unmount component', async () => {
|
||||||
const { host, app, instance } = define(() => {
|
const { host, app, instance } = define(() => {
|
||||||
const count = ref(0)
|
const count = ref(0)
|
||||||
|
|
|
@ -276,7 +276,7 @@ export function createComponent(
|
||||||
onScopeDispose(() => unmountComponent(instance), true)
|
onScopeDispose(() => unmountComponent(instance), true)
|
||||||
|
|
||||||
if (!isHydrating && _insertionParent) {
|
if (!isHydrating && _insertionParent) {
|
||||||
insert(instance.block, _insertionParent, _insertionAnchor)
|
mountComponent(instance, _insertionParent, _insertionAnchor)
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
Loading…
Reference in New Issue