]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-vapor): adjust children generation order for hydration
authordaiwei <daiwei521@126.com>
Fri, 1 Aug 2025 07:12:11 +0000 (15:12 +0800)
committerdaiwei <daiwei521@126.com>
Fri, 1 Aug 2025 07:12:11 +0000 (15:12 +0800)
packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap
packages/compiler-vapor/__tests__/compile.spec.ts
packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap
packages/compiler-vapor/src/generators/block.ts
packages/compiler-vapor/src/generators/template.ts

index b10a98d32cba702483ed45d2d0175ec8232ffc37..e0520c37db8495517d73bf0c1047cc56cbc68103 100644 (file)
@@ -212,6 +212,20 @@ export function render(_ctx) {
 }"
 `;
 
+exports[`compile > execution order > with insertionState 1`] = `
+"import { resolveComponent as _resolveComponent, setInsertionState as _setInsertionState, createSlot as _createSlot, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
+const t0 = _template("<div></div>")
+
+export function render(_ctx) {
+  const _component_Comp = _resolveComponent("Comp")
+  const n1 = t0()
+  _setInsertionState(n1)
+  const n0 = _createSlot("default", null)
+  const n2 = _createComponentWithFallback(_component_Comp)
+  return [n1, n2]
+}"
+`;
+
 exports[`compile > execution order > with v-once 1`] = `
 "import { child as _child, next as _next, nthChild as _nthChild, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
 const t0 = _template("<div><span> </span> <br> </div>", true)
index 178021d13dd21896f55f6fbbce381ccb4a082e3d..319cef431d7019586c6330766071d8d3785d20d4 100644 (file)
@@ -247,6 +247,7 @@ describe('compile', () => {
     _setText(x0, _toDisplayString(_ctx.bar))`,
       )
     })
+
     test('with v-once', () => {
       const code = compile(
         `<div>
@@ -261,5 +262,10 @@ describe('compile', () => {
     _setText(n2, " " + _toDisplayString(_ctx.baz))`,
       )
     })
+
+    test('with insertionState', () => {
+      const code = compile(`<div><slot /></div><Comp/>`)
+      expect(code).matchSnapshot()
+    })
   })
 })
index 7aa56aa9c2f880745a40a482fc1fbdfe419e2dcd..3188a866070b762926636a68204f4fd9f157758e 100644 (file)
@@ -343,8 +343,8 @@ const t2 = _template("<form></form>")
 
 export function render(_ctx) {
   const n1 = t1()
-  const n3 = t2()
   const n0 = t0()
+  const n3 = t2()
   const n2 = t2()
   _insert(n0, n1)
   _insert(n2, n3)
index 30347394756b90e7c63a385a91dc745597b43f4c..a4f98dfdffa3269074815cb6d8916be484aad95c 100644 (file)
@@ -65,7 +65,9 @@ export function genBlockContent(
     push(...genSelf(child, context))
   }
   for (const child of dynamic.children) {
-    push(...genChildren(child, context, push, `n${child.id!}`))
+    if (!child.hasDynamicChild) {
+      push(...genChildren(child, context, push, `n${child.id!}`))
+    }
   }
 
   push(...genOperations(operation, context))
index 5a066b09e9a622435465988ab2af5cb4736222e6..61f50835a5682fe315aac35fba95b07d4eb42362 100644 (file)
@@ -24,7 +24,7 @@ export function genSelf(
   context: CodegenContext,
 ): CodeFragment[] {
   const [frag, push] = buildCodeFragment()
-  const { id, template, operation } = dynamic
+  const { id, template, operation, hasDynamicChild } = dynamic
 
   if (id !== undefined && template !== undefined) {
     push(NEWLINE, `const n${id} = t${template}()`)
@@ -35,6 +35,10 @@ export function genSelf(
     push(...genOperationWithInsertionState(operation, context))
   }
 
+  if (hasDynamicChild) {
+    push(...genChildren(dynamic, context, push, `n${id}`))
+  }
+
   return frag
 }
 
@@ -96,7 +100,7 @@ export function genChildren(
       }
     }
 
-    if (id === child.anchor) {
+    if (id === child.anchor && !child.hasDynamicChild) {
       push(...genSelf(child, context))
     }