Skip to content

Commit a33a563

Browse files
committed
fix(compiler-vapor): adjust children generation order for hydration
1 parent 07fd7e4 commit a33a563

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ export function render(_ctx) {
212212
}"
213213
`;
214214
215+
exports[`compile > execution order > with insertionState 1`] = `
216+
"import { resolveComponent as _resolveComponent, setInsertionState as _setInsertionState, createSlot as _createSlot, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
217+
const t0 = _template("<div></div>")
218+
219+
export function render(_ctx) {
220+
const _component_Comp = _resolveComponent("Comp")
221+
const n1 = t0()
222+
_setInsertionState(n1)
223+
const n0 = _createSlot("default", null)
224+
const n2 = _createComponentWithFallback(_component_Comp)
225+
return [n1, n2]
226+
}"
227+
`;
228+
215229
exports[`compile > execution order > with v-once 1`] = `
216230
"import { child as _child, next as _next, nthChild as _nthChild, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
217231
const t0 = _template("<div><span> </span> <br> </div>", true)

packages/compiler-vapor/__tests__/compile.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ describe('compile', () => {
247247
_setText(x0, _toDisplayString(_ctx.bar))`,
248248
)
249249
})
250+
250251
test('with v-once', () => {
251252
const code = compile(
252253
`<div>
@@ -261,5 +262,10 @@ describe('compile', () => {
261262
_setText(n2, " " + _toDisplayString(_ctx.baz))`,
262263
)
263264
})
265+
266+
test('with insertionState', () => {
267+
const code = compile(`<div><slot /></div><Comp/>`)
268+
expect(code).matchSnapshot()
269+
})
264270
})
265271
})

packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ const t2 = _template("<form></form>")
343343
344344
export function render(_ctx) {
345345
const n1 = t1()
346-
const n3 = t2()
347346
const n0 = t0()
347+
const n3 = t2()
348348
const n2 = t2()
349349
_insert(n0, n1)
350350
_insert(n2, n3)

packages/compiler-vapor/src/generators/block.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ export function genBlockContent(
6565
push(...genSelf(child, context))
6666
}
6767
for (const child of dynamic.children) {
68-
push(...genChildren(child, context, push, `n${child.id!}`))
68+
if (!child.hasDynamicChild) {
69+
push(...genChildren(child, context, push, `n${child.id!}`))
70+
}
6971
}
7072

7173
push(...genOperations(operation, context))

packages/compiler-vapor/src/generators/template.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function genSelf(
2424
context: CodegenContext,
2525
): CodeFragment[] {
2626
const [frag, push] = buildCodeFragment()
27-
const { id, template, operation } = dynamic
27+
const { id, template, operation, hasDynamicChild } = dynamic
2828

2929
if (id !== undefined && template !== undefined) {
3030
push(NEWLINE, `const n${id} = t${template}()`)
@@ -35,6 +35,10 @@ export function genSelf(
3535
push(...genOperationWithInsertionState(operation, context))
3636
}
3737

38+
if (hasDynamicChild) {
39+
push(...genChildren(dynamic, context, push, `n${id}`))
40+
}
41+
3842
return frag
3943
}
4044

@@ -96,7 +100,7 @@ export function genChildren(
96100
}
97101
}
98102

99-
if (id === child.anchor) {
103+
if (id === child.anchor && !child.hasDynamicChild) {
100104
push(...genSelf(child, context))
101105
}
102106

0 commit comments

Comments
 (0)