]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-vapor): properly mount component when using setInsertionState (#13041)
authoredison <daiwei521@126.com>
Fri, 20 Jun 2025 00:29:50 +0000 (08:29 +0800)
committerGitHub <noreply@github.com>
Fri, 20 Jun 2025 00:29:50 +0000 (08:29 +0800)
packages/runtime-vapor/__tests__/component.spec.ts
packages/runtime-vapor/src/component.ts

index 5fdff8eafe4453b437af4b07e561191639c1d045..22294b1e7356d45928b435c752984b6498bd2d71 100644 (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)
index c6602ec961bc23ea27bad8cf72c3381a7a9562f5..deec96cb0a27a094ffcca10341ae5d2b1bbd92b0 100644 (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