fix(runtime-vapor): properly mount component when using setInsertionState (#13041)

This commit is contained in:
edison 2025-06-20 08:29:50 +08:00 committed by GitHub
parent 504fa10de3
commit b9dc8658cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View File

@ -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)

View File

@ -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