Skip to content

Commit 128eb21

Browse files
committed
fix(compiler): adjust children generation order for hydration
Copied from https://github.com/vuejs/core/pull/13729/files
1 parent 264c7be commit 128eb21

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

packages/compiler/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/src/generators/template.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function genSelf(
2323
context: CodegenContext,
2424
): CodeFragment[] {
2525
const [frag, push] = buildCodeFragment()
26-
const { id, template, operation } = dynamic
26+
const { id, template, operation, hasDynamicChild } = dynamic
2727

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

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

@@ -49,7 +53,6 @@ export function genChildren(
4953

5054
let offset = 0
5155
let prev: [variable: string, elementIndex: number] | undefined
52-
const childrenToGen: [IRDynamicInfo, string][] = []
5356

5457
for (const [index, child] of children.entries()) {
5558
if (child.flags & DynamicFlag.NON_TEMPLATE) {
@@ -93,7 +96,7 @@ export function genChildren(
9396
pushBlock(...init)
9497
}
9598

96-
if (id === child.anchor) {
99+
if (id === child.anchor && !child.hasDynamicChild) {
97100
push(...genSelf(child, context))
98101
}
99102

@@ -102,13 +105,7 @@ export function genChildren(
102105
}
103106

104107
prev = [variable, elementIndex]
105-
childrenToGen.push([child, variable])
106-
}
107-
108-
if (childrenToGen.length) {
109-
for (const [child, from] of childrenToGen) {
110-
push(...genChildren(child, context, pushBlock, from))
111-
}
108+
push(...genChildren(child, context, pushBlock, variable))
112109
}
113110

114111
return frag

packages/compiler/test/transforms/__snapshots__/transformChildren.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ exports[`compiler: children transform > efficient traversal 1`] = `
2323
"
2424
const n3 = t0()
2525
const p0 = _next(_child(n3))
26-
const p1 = _next(p0)
27-
const p2 = _next(p1)
2826
const n0 = _child(p0)
27+
const p1 = _next(p0)
2928
const n1 = _child(p1)
29+
const p2 = _next(p1)
3030
const n2 = _child(p2)
3131
const x0 = _child(n0)
3232
_setNodes(x0, () => ({ msg: msg }))

0 commit comments

Comments
 (0)