Skip to content

Commit d1d35cb

Browse files
authored
feat(vapor): hydration (#13226)
1 parent 7204cb6 commit d1d35cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5534
-2201
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"pug": "^3.0.3",
9999
"puppeteer": "~24.16.2",
100100
"rimraf": "^6.0.1",
101-
"rollup": "4.50.1",
101+
"rollup": "^4.52.5",
102102
"rollup-plugin-dts": "^6.2.3",
103103
"rollup-plugin-esbuild": "^6.2.1",
104104
"rollup-plugin-polyfill-node": "^0.13.0",

packages/compiler-sfc/src/compileScript.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,11 @@ export function compileScript(
10211021
: ''
10221022
// wrap setup code with function.
10231023
if (ctx.isTS) {
1024+
// in SSR, always use defineComponent, so __vapor flag is required
1025+
if (ssr && vapor) {
1026+
runtimeOptions += `\n __vapor: true,`
1027+
}
1028+
10241029
// for TS, make sure the exported type is still valid type with
10251030
// correct props information
10261031
// we have to use object spread for types to be merged properly

packages/compiler-ssr/__tests__/ssrVIf.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ describe('ssr: v-if', () => {
8282
test('<template v-if> (text)', () => {
8383
expect(compile(`<template v-if="foo">hello</template>`).code)
8484
.toMatchInlineSnapshot(`
85-
"
86-
return function ssrRender(_ctx, _push, _parent, _attrs) {
87-
if (_ctx.foo) {
88-
_push(\`<!--[-->hello<!--]-->\`)
89-
} else {
90-
_push(\`<!---->\`)
91-
}
92-
}"
93-
`)
85+
"
86+
return function ssrRender(_ctx, _push, _parent, _attrs) {
87+
if (_ctx.foo) {
88+
_push(\`<!--[-->hello<!--]-->\`)
89+
} else {
90+
_push(\`<!---->\`)
91+
}
92+
}"
93+
`)
9494
})
9595

9696
test('<template v-if> (single element)', () => {

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

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

33
exports[`compile > bindings 1`] = `
4-
"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
4+
"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
55
const t0 = _template("<div> </div>", true)
66
77
export function render(_ctx, $props, $emit, $attrs, $slots) {
88
const n0 = t0()
9-
const x0 = _child(n0)
9+
const x0 = _txt(n0)
1010
_renderEffect(() => _setText(x0, "count is " + _toDisplayString(_ctx.count) + "."))
1111
return n0
1212
}"
@@ -38,7 +38,7 @@ export function render(_ctx) {
3838
"default": () => {
3939
const n0 = _createIf(() => (true), () => {
4040
const n3 = t0()
41-
_setInsertionState(n3)
41+
_setInsertionState(n3, null, true)
4242
const n2 = _createComponentWithFallback(_component_Bar)
4343
_withVaporDirectives(n2, [[_directive_hello, void 0, void 0, { world: true }]])
4444
return n3
@@ -157,8 +157,8 @@ export function render(_ctx, $props, $emit, $attrs, $slots) {
157157
const _component_Comp = _resolveComponent("Comp")
158158
const n0 = t0()
159159
const n3 = t1()
160-
const n2 = _child(n3)
161-
_setInsertionState(n3, 0)
160+
const n2 = _child(n3, 1)
161+
_setInsertionState(n3, 0, true)
162162
const n1 = _createComponentWithFallback(_component_Comp)
163163
_renderEffect(() => {
164164
_setProp(n3, "id", _ctx.foo)
@@ -180,13 +180,13 @@ export function render(_ctx) {
180180
`;
181181
182182
exports[`compile > dynamic root nodes and interpolation 1`] = `
183-
"import { child as _child, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, delegateEvents as _delegateEvents, template as _template } from 'vue';
183+
"import { txt as _txt, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, delegateEvents as _delegateEvents, template as _template } from 'vue';
184184
const t0 = _template("<button> </button>", true)
185185
_delegateEvents("click")
186186
187187
export function render(_ctx) {
188188
const n0 = t0()
189-
const x0 = _child(n0)
189+
const x0 = _txt(n0)
190190
n0.$evtclick = e => _ctx.handleClick(e)
191191
_renderEffect(() => {
192192
const _count = _ctx.count
@@ -198,12 +198,12 @@ export function render(_ctx) {
198198
`;
199199
200200
exports[`compile > execution order > basic 1`] = `
201-
"import { child as _child, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
201+
"import { txt as _txt, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
202202
const t0 = _template("<div> </div>", true)
203203
204204
export function render(_ctx) {
205205
const n0 = t0()
206-
const x0 = _child(n0)
206+
const x0 = _txt(n0)
207207
_renderEffect(() => {
208208
_setProp(n0, "id", _ctx.foo)
209209
_setText(x0, _toDisplayString(_ctx.bar))
@@ -212,32 +212,56 @@ export function render(_ctx) {
212212
}"
213213
`;
214214
215+
exports[`compile > execution order > setInsertionState > next, child and nthChild should be above the setInsertionState 1`] = `
216+
"import { resolveComponent as _resolveComponent, child as _child, next as _next, setInsertionState as _setInsertionState, createComponentWithFallback as _createComponentWithFallback, nthChild as _nthChild, createIf as _createIf, setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
217+
const t0 = _template("<div></div>")
218+
const t1 = _template("<div><div></div><!><div></div><!><div><button></button></div></div>", true)
219+
220+
export function render(_ctx) {
221+
const _component_Comp = _resolveComponent("Comp")
222+
const n6 = t1()
223+
const n5 = _next(_child(n6), 1)
224+
const n7 = _nthChild(n6, 3, 3)
225+
const p0 = _next(n7, 4)
226+
const n4 = _child(p0, 0)
227+
_setInsertionState(n6, n5)
228+
const n0 = _createComponentWithFallback(_component_Comp)
229+
_setInsertionState(n6, n7, true)
230+
const n1 = _createIf(() => (true), () => {
231+
const n3 = t0()
232+
return n3
233+
})
234+
_renderEffect(() => _setProp(n4, "disabled", _ctx.foo))
235+
return n6
236+
}"
237+
`;
238+
215239
exports[`compile > execution order > with insertionState 1`] = `
216240
"import { resolveComponent as _resolveComponent, child as _child, setInsertionState as _setInsertionState, createSlot as _createSlot, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
217241
const t0 = _template("<div><div></div></div>", true)
218242
219243
export function render(_ctx) {
220244
const _component_Comp = _resolveComponent("Comp")
221245
const n3 = t0()
222-
const n1 = _child(n3)
223-
_setInsertionState(n1)
246+
const n1 = _child(n3, 0)
247+
_setInsertionState(n1, null, true)
224248
const n0 = _createSlot("default", null)
225-
_setInsertionState(n3)
249+
_setInsertionState(n3, 1, true)
226250
const n2 = _createComponentWithFallback(_component_Comp)
227251
return n3
228252
}"
229253
`;
230254
231255
exports[`compile > execution order > with v-once 1`] = `
232-
"import { child as _child, next as _next, nthChild as _nthChild, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
256+
"import { child as _child, next as _next, nthChild as _nthChild, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
233257
const t0 = _template("<div><span> </span> <br> </div>", true)
234258
235259
export function render(_ctx) {
236260
const n3 = t0()
237-
const n0 = _child(n3)
238-
const n1 = _next(n0)
239-
const n2 = _nthChild(n3, 3)
240-
const x0 = _child(n0)
261+
const n0 = _child(n3, 0)
262+
const n1 = _next(n0, 1)
263+
const n2 = _nthChild(n3, 3, 3)
264+
const x0 = _txt(n0)
241265
_setText(x0, _toDisplayString(_ctx.foo))
242266
_renderEffect(() => {
243267
_setText(n1, " " + _toDisplayString(_ctx.bar))
@@ -280,30 +304,6 @@ export function render(_ctx) {
280304
}"
281305
`;
282306
283-
exports[`compile > setInsertionState > next, child and nthChild should be above the setInsertionState 1`] = `
284-
"import { resolveComponent as _resolveComponent, child as _child, next as _next, setInsertionState as _setInsertionState, createComponentWithFallback as _createComponentWithFallback, nthChild as _nthChild, createIf as _createIf, setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
285-
const t0 = _template("<div></div>")
286-
const t1 = _template("<div><div></div><!><div></div><!><div><button></button></div></div>", true)
287-
288-
export function render(_ctx) {
289-
const _component_Comp = _resolveComponent("Comp")
290-
const n6 = t1()
291-
const n5 = _next(_child(n6))
292-
const n7 = _nthChild(n6, 3)
293-
const p0 = _next(n7)
294-
const n4 = _child(p0)
295-
_setInsertionState(n6, n5)
296-
const n0 = _createComponentWithFallback(_component_Comp)
297-
_setInsertionState(n6, n7)
298-
const n1 = _createIf(() => (true), () => {
299-
const n3 = t0()
300-
return n3
301-
})
302-
_renderEffect(() => _setProp(n4, "disabled", _ctx.foo))
303-
return n6
304-
}"
305-
`;
306-
307307
exports[`compile > static + dynamic root 1`] = `
308308
"import { toDisplayString as _toDisplayString, setText as _setText, template as _template } from 'vue';
309309
const t0 = _template(" ")

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,19 @@ describe('compile', () => {
221221
})
222222
})
223223

224-
describe('setInsertionState', () => {
225-
test('next, child and nthChild should be above the setInsertionState', () => {
226-
const code = compile(`
224+
describe('execution order', () => {
225+
test('basic', () => {
226+
const code = compile(`<div :id="foo">{{ bar }}</div>`)
227+
expect(code).matchSnapshot()
228+
expect(code).contains(
229+
`_setProp(n0, "id", _ctx.foo)
230+
_setText(x0, _toDisplayString(_ctx.bar))`,
231+
)
232+
})
233+
234+
describe('setInsertionState', () => {
235+
test('next, child and nthChild should be above the setInsertionState', () => {
236+
const code = compile(`
227237
<div>
228238
<div />
229239
<Comp />
@@ -234,18 +244,8 @@ describe('compile', () => {
234244
</div>
235245
</div>
236246
`)
237-
expect(code).toMatchSnapshot()
238-
})
239-
})
240-
241-
describe('execution order', () => {
242-
test('basic', () => {
243-
const code = compile(`<div :id="foo">{{ bar }}</div>`)
244-
expect(code).matchSnapshot()
245-
expect(code).contains(
246-
`_setProp(n0, "id", _ctx.foo)
247-
_setText(x0, _toDisplayString(_ctx.bar))`,
248-
)
247+
expect(code).toMatchSnapshot()
248+
})
249249
})
250250

251251
test('with v-once', () => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function render(_ctx) {
5151
return n5
5252
}, () => {
5353
const n14 = t2()
54-
_setInsertionState(n14, 0)
54+
_setInsertionState(n14, 0, true)
5555
const n9 = _createIf(() => (_ctx.c), () => {
5656
const n11 = t1()
5757
return n11

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ export function render(_ctx) {
4242
`;
4343

4444
exports[`compiler: expression > empty interpolation 4`] = `
45-
"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
45+
"import { child as _child, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
4646
const t0 = _template("<div> </div>", true)
4747
4848
export function render(_ctx) {
4949
const n1 = t0()
50-
const n0 = _child(n1)
51-
const x1 = _child(n1)
50+
const n0 = _child(n1, 0)
51+
const x1 = _txt(n1)
5252
_renderEffect(() => {
5353
const _foo = _ctx.foo
5454
_setText(n0, _toDisplayString(_foo))
@@ -81,13 +81,13 @@ export function render(_ctx, $props, $emit, $attrs, $slots) {
8181
`;
8282

8383
exports[`compiler: expression > update expression 1`] = `
84-
"import { child as _child, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
84+
"import { child as _child, txt as _txt, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
8585
const t0 = _template("<div> </div>", true)
8686
8787
export function render(_ctx) {
8888
const n1 = t0()
89-
const n0 = _child(n1)
90-
const x1 = _child(n1)
89+
const n0 = _child(n1, 0)
90+
const x1 = _txt(n1)
9191
_renderEffect(() => {
9292
const _String = String
9393
const _foo = _ctx.foo

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const t1 = _template("<div><div></div><!><div></div></div>", true)
77
88
export function render(_ctx) {
99
const n4 = t1()
10-
const n3 = _next(_child(n4))
11-
_setInsertionState(n4, n3)
10+
const n3 = _next(_child(n4), 1)
11+
_setInsertionState(n4, n3, true)
1212
const n0 = _createIf(() => (1), () => {
1313
const n2 = t0()
1414
return n2
@@ -18,16 +18,16 @@ export function render(_ctx) {
1818
`;
1919

2020
exports[`compiler: children transform > children & sibling references 1`] = `
21-
"import { child as _child, next as _next, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
21+
"import { child as _child, next as _next, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
2222
const t0 = _template("<div><p> </p> <p> </p></div>", true)
2323
2424
export function render(_ctx) {
2525
const n3 = t0()
26-
const n0 = _child(n3)
27-
const n1 = _next(n0)
28-
const n2 = _next(n1)
29-
const x0 = _child(n0)
30-
const x2 = _child(n2)
26+
const n0 = _child(n3, 0)
27+
const n1 = _next(n0, 1)
28+
const n2 = _next(n1, 2)
29+
const x0 = _txt(n0)
30+
const x2 = _txt(n2)
3131
_renderEffect(() => {
3232
_setText(x0, _toDisplayString(_ctx.first))
3333
_setText(n1, " " + _toDisplayString(_ctx.second) + " " + _toDisplayString(_ctx.third) + " ")
@@ -38,33 +38,33 @@ export function render(_ctx) {
3838
`;
3939

4040
exports[`compiler: children transform > efficient find 1`] = `
41-
"import { child as _child, nthChild as _nthChild, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
41+
"import { child as _child, nthChild as _nthChild, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
4242
const t0 = _template("<div><div>x</div><div>x</div><div> </div></div>", true)
4343
4444
export function render(_ctx) {
4545
const n1 = t0()
46-
const n0 = _nthChild(n1, 2)
47-
const x0 = _child(n0)
46+
const n0 = _nthChild(n1, 2, 2)
47+
const x0 = _txt(n0)
4848
_renderEffect(() => _setText(x0, _toDisplayString(_ctx.msg)))
4949
return n1
5050
}"
5151
`;
5252

5353
exports[`compiler: children transform > efficient traversal 1`] = `
54-
"import { child as _child, next as _next, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
54+
"import { child as _child, next as _next, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
5555
const t0 = _template("<div><div>x</div><div><span> </span></div><div><span> </span></div><div><span> </span></div></div>", true)
5656
5757
export function render(_ctx) {
5858
const n3 = t0()
59-
const p0 = _next(_child(n3))
60-
const n0 = _child(p0)
61-
const p1 = _next(p0)
62-
const n1 = _child(p1)
63-
const p2 = _next(p1)
64-
const n2 = _child(p2)
65-
const x0 = _child(n0)
66-
const x1 = _child(n1)
67-
const x2 = _child(n2)
59+
const p0 = _next(_child(n3), 1)
60+
const n0 = _child(p0, 0)
61+
const p1 = _next(p0, 2)
62+
const n1 = _child(p1, 0)
63+
const p2 = _next(p1, 3)
64+
const n2 = _child(p2, 0)
65+
const x0 = _txt(n0)
66+
const x1 = _txt(n1)
67+
const x2 = _txt(n2)
6868
_renderEffect(() => {
6969
const _msg = _ctx.msg
7070
_setText(x0, _toDisplayString(_msg))

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

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

3+
exports[`compiler: element transform > checkbox with static indeterminate 1`] = `
4+
"import { setProp as _setProp, template as _template } from 'vue';
5+
const t0 = _template("<input type=\\"checkbox\\">", true)
6+
7+
export function render(_ctx) {
8+
const n0 = t0()
9+
_setProp(n0, "indeterminate", "")
10+
return n0
11+
}"
12+
`;
13+
314
exports[`compiler: element transform > component > cache v-on expression with unique handler name 1`] = `
415
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback } from 'vue';
516

0 commit comments

Comments
 (0)