Skip to content

Commit c50fb0e

Browse files
committed
fix(compiler-vapor): move setInsertionState to the end to prevent nthChild mismatch
1 parent 2696f14 commit c50fb0e

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function render(_ctx) {
2626
`;
2727

2828
exports[`compile > custom directive > component 1`] = `
29-
"import { resolveComponent as _resolveComponent, resolveDirective as _resolveDirective, setInsertionState as _setInsertionState, createComponentWithFallback as _createComponentWithFallback, withVaporDirectives as _withVaporDirectives, createIf as _createIf, template as _template } from 'vue';
29+
"import { resolveComponent as _resolveComponent, resolveDirective as _resolveDirective, createComponentWithFallback as _createComponentWithFallback, withVaporDirectives as _withVaporDirectives, setInsertionState as _setInsertionState, createIf as _createIf, template as _template } from 'vue';
3030
const t0 = _template("<div></div>")
3131
3232
export function render(_ctx) {
@@ -38,9 +38,9 @@ export function render(_ctx) {
3838
"default": () => {
3939
const n0 = _createIf(() => (true), () => {
4040
const n3 = t0()
41-
_setInsertionState(n3)
4241
const n2 = _createComponentWithFallback(_component_Bar)
4342
_withVaporDirectives(n2, [[_directive_hello, void 0, void 0, { world: true }]])
43+
_setInsertionState(n3)
4444
return n3
4545
})
4646
return n0
@@ -149,16 +149,16 @@ export function render(_ctx, $props, $emit, $attrs, $slots) {
149149
`;
150150
151151
exports[`compile > directives > v-pre > should not affect siblings after it 1`] = `
152-
"import { resolveComponent as _resolveComponent, setInsertionState as _setInsertionState, createComponentWithFallback as _createComponentWithFallback, child as _child, toDisplayString as _toDisplayString, setText as _setText, setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
152+
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback, setInsertionState as _setInsertionState, child as _child, toDisplayString as _toDisplayString, setText as _setText, setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
153153
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div>")
154154
const t1 = _template("<div> </div>")
155155
156156
export function render(_ctx, $props, $emit, $attrs, $slots) {
157157
const _component_Comp = _resolveComponent("Comp")
158158
const n0 = t0()
159159
const n3 = t1()
160-
_setInsertionState(n3, 0)
161160
const n1 = _createComponentWithFallback(_component_Comp)
161+
_setInsertionState(n3, 0)
162162
const n2 = _child(n3)
163163
_renderEffect(() => {
164164
_setText(n2, _toDisplayString(_ctx.bar))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`compiler: children transform > anchor insertion in middle 1`] = `
4-
"import { child as _child, next as _next, setInsertionState as _setInsertionState, createIf as _createIf, template as _template } from 'vue';
4+
"import { child as _child, next as _next, createIf as _createIf, setInsertionState as _setInsertionState, template as _template } from 'vue';
55
const t0 = _template("<div></div>")
66
const t1 = _template("<div><div></div><!><div></div></div>", true)
77
88
export function render(_ctx) {
99
const n4 = t1()
1010
const n3 = _next(_child(n4))
11-
_setInsertionState(n4, n3)
1211
const n0 = _createIf(() => (1), () => {
1312
const n2 = t0()
1413
return n2
1514
}, null, true)
15+
_setInsertionState(n4, n3)
1616
return n4
1717
}"
1818
`;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ export function render(_ctx) {
6565
`;
6666

6767
exports[`compiler: v-for > nested v-for 1`] = `
68-
"import { setInsertionState as _setInsertionState, child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue';
68+
"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, setInsertionState as _setInsertionState, template as _template } from 'vue';
6969
const t0 = _template("<span> </span>")
7070
const t1 = _template("<div></div>", true)
7171
7272
export function render(_ctx) {
7373
const n0 = _createFor(() => (_ctx.list), (_for_item0) => {
7474
const n5 = t1()
75-
_setInsertionState(n5)
7675
const n2 = _createFor(() => (_for_item0.value), (_for_item1) => {
7776
const n4 = t0()
7877
const x4 = _child(n4)
7978
_renderEffect(() => _setText(x4, _toDisplayString(_for_item1.value+_for_item0.value)))
8079
return n4
8180
}, null, 1)
81+
_setInsertionState(n5)
8282
return n5
8383
})
8484
return n0

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ export function render(_ctx) {
3636
`;
3737

3838
exports[`compiler: v-once > on component 1`] = `
39-
"import { resolveComponent as _resolveComponent, setInsertionState as _setInsertionState, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
39+
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback, setInsertionState as _setInsertionState, template as _template } from 'vue';
4040
const t0 = _template("<div></div>", true)
4141
4242
export function render(_ctx) {
4343
const _component_Comp = _resolveComponent("Comp")
4444
const n1 = t0()
45-
_setInsertionState(n1)
4645
const n0 = _createComponentWithFallback(_component_Comp, { id: () => (_ctx.foo) }, null, null, true)
46+
_setInsertionState(n1)
4747
return n1
4848
}"
4949
`;

packages/compiler-vapor/__tests__/transforms/transformChildren.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ describe('compiler: children transform', () => {
6969
</div>`,
7070
)
7171
// ensure the insertion anchor is generated before the insertion statement
72-
expect(code).toMatch(`const n3 = _next(_child(n4))
73-
_setInsertionState(n4, n3)`)
72+
expect(code).toMatch(`const n3 = _next(_child(n4))`)
73+
expect(code).toMatch(`_setInsertionState(n4, n3)`)
7474
expect(code).toMatchSnapshot()
7575
})
7676
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ export function genOperationWithInsertionState(
4343
context: CodegenContext,
4444
): CodeFragment[] {
4545
const [frag, push] = buildCodeFragment()
46+
push(...genOperation(oper, context))
4647
if (isBlockOperation(oper) && oper.parent) {
4748
push(...genInsertionstate(oper, context))
4849
}
49-
push(...genOperation(oper, context))
5050
return frag
5151
}
5252

0 commit comments

Comments
 (0)