Skip to content

Commit b9dc865

Browse files
authored
fix(runtime-vapor): properly mount component when using setInsertionState (#13041)
1 parent 504fa10 commit b9dc865

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/runtime-vapor/__tests__/component.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
type Ref,
33
inject,
44
nextTick,
5+
onMounted,
56
onUpdated,
67
provide,
78
ref,
@@ -13,6 +14,7 @@ import {
1314
createIf,
1415
createTextNode,
1516
renderEffect,
17+
setInsertionState,
1618
template,
1719
} from '../src'
1820
import { makeRender } from './_utils'
@@ -266,6 +268,29 @@ describe('component', () => {
266268
expect(spy).toHaveBeenCalledTimes(2)
267269
})
268270

271+
it('properly mount child component when using setInsertionState', async () => {
272+
const spy = vi.fn()
273+
274+
const { component: Comp } = define({
275+
setup() {
276+
onMounted(spy)
277+
return template('<h1>hi</h1>')()
278+
},
279+
})
280+
281+
const { host } = define({
282+
setup() {
283+
const n2 = template('<div></div>', true)()
284+
setInsertionState(n2 as any)
285+
createComponent(Comp)
286+
return n2
287+
},
288+
}).render()
289+
290+
expect(host.innerHTML).toBe('<div><h1>hi</h1></div>')
291+
expect(spy).toHaveBeenCalledTimes(1)
292+
})
293+
269294
it('unmount component', async () => {
270295
const { host, app, instance } = define(() => {
271296
const count = ref(0)

packages/runtime-vapor/src/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export function createComponent(
276276
onScopeDispose(() => unmountComponent(instance), true)
277277

278278
if (!isHydrating && _insertionParent) {
279-
insert(instance.block, _insertionParent, _insertionAnchor)
279+
mountComponent(instance, _insertionParent, _insertionAnchor)
280280
}
281281

282282
return instance

0 commit comments

Comments
 (0)