Skip to content

Commit e39b4b7

Browse files
lots of progress, couple of failing tests around selects
1 parent df67afe commit e39b4b7

File tree

52 files changed

+562
-256
lines changed

Some content is hidden

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

52 files changed

+562
-256
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ jobs:
5757
- run: pnpm install --frozen-lockfile
5858
- run: pnpm playwright install chromium
5959
- run: pnpm test runtime-runes
60+
- run: pnpm test server-side-rendering
6061
env:
6162
CI: true
6263
SVELTE_NO_ASYNC: true

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export function server_component(analysis, options) {
240240
b.call(
241241
'$$payload.child',
242242
b.arrow(
243-
[b.object_pattern([b.init('$$payload', b.id('$$payload'))])],
243+
[b.id('$$payload')],
244244
b.block([
245245
.../** @type {Statement[]} */ (instance.body),
246246
.../** @type {Statement[]} */ (template.body)
@@ -304,7 +304,7 @@ export function server_component(analysis, options) {
304304
const code = b.literal(render_stylesheet(analysis.source, analysis, options).code);
305305

306306
body.push(b.const('$$css', b.object([b.init('hash', hash), b.init('code', code)])));
307-
component_block.body.unshift(b.stmt(b.call('$$payload.css.add', b.id('$$css'))));
307+
component_block.body.unshift(b.stmt(b.call('$$payload.global.css.add', b.id('$$css'))));
308308
}
309309

310310
let should_inject_props =

packages/svelte/src/compiler/phases/3-transform/server/visitors/EachBlock.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ export function EachBlock(node, context) {
4444
);
4545

4646
if (node.fallback) {
47-
const open = b.stmt(b.call(b.member(b.id('$$payload.out'), b.id('push')), block_open));
47+
const open = b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), block_open));
4848

4949
const fallback = /** @type {BlockStatement} */ (context.visit(node.fallback));
5050

5151
fallback.body.unshift(
52-
b.stmt(b.call(b.member(b.id('$$payload.out'), b.id('push')), b.literal(BLOCK_OPEN_ELSE)))
52+
b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), b.literal(BLOCK_OPEN_ELSE)))
5353
);
5454

5555
state.template.push(

packages/svelte/src/compiler/phases/3-transform/server/visitors/IfBlock.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ export function IfBlock(node, context) {
1717
? /** @type {BlockStatement} */ (context.visit(node.alternate))
1818
: b.block([]);
1919

20-
consequent.body.unshift(
21-
b.stmt(b.call(b.member(b.id('$$payload.out'), b.id('push')), block_open))
22-
);
20+
consequent.body.unshift(b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), block_open)));
2321

2422
alternate.body.unshift(
25-
b.stmt(b.call(b.member(b.id('$$payload.out'), b.id('push')), b.literal(BLOCK_OPEN_ELSE)))
23+
b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), b.literal(BLOCK_OPEN_ELSE)))
2624
);
2725

2826
context.state.template.push(b.if(test, consequent, alternate), block_close);

packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function RegularElement(node, context) {
9292
b.stmt(
9393
b.assignment(
9494
'=',
95-
b.id('$$payload.select_value'),
95+
b.id('$$payload.local.select_value'),
9696
b.member(
9797
build_spread_object(
9898
node,
@@ -113,7 +113,7 @@ export function RegularElement(node, context) {
113113
);
114114
} else if (value) {
115115
select_with_value = true;
116-
const left = b.id('$$payload.select_value');
116+
const left = b.id('$$payload.local.select_value');
117117
if (value.type === 'Attribute') {
118118
state.template.push(
119119
b.stmt(b.assignment('=', left, build_attribute_value(value.value, context)))
@@ -151,7 +151,11 @@ export function RegularElement(node, context) {
151151
b.call(
152152
'$.valueless_option',
153153
b.id('$$payload'),
154-
b.thunk(b.block([...inner_state.init, ...build_template(inner_state.template)]))
154+
b.arrow(
155+
[b.id('$$payload')],
156+
b.block([...inner_state.init, ...build_template(inner_state.template)]),
157+
context.state.analysis.has_blocking_await
158+
)
155159
)
156160
)
157161
);

packages/svelte/src/compiler/phases/3-transform/server/visitors/SnippetBlock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function SnippetBlock(node, context) {
1717
b.call(
1818
'$$payload.child',
1919
b.arrow(
20-
[b.object_pattern([b.init('$$payload', b.id('$$payload'))])],
20+
[b.id('$$payload')],
2121
/** @type {BlockStatement} */ (context.visit(node.body)),
2222
node.metadata.has_await
2323
)

packages/svelte/src/compiler/phases/3-transform/server/visitors/SvelteHead.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ export function SvelteHead(node, context) {
1111
const block = /** @type {BlockStatement} */ (context.visit(node.fragment));
1212

1313
context.state.template.push(
14-
b.stmt(b.call('$.head', b.id('$$payload'), b.arrow([b.id('$$payload')], block)))
14+
b.stmt(
15+
b.call(
16+
'$.head',
17+
b.id('$$payload'),
18+
// same thing as elsewhere; this will create more async functions than necessary but should never be _wrong_
19+
// because the component rendering this head block will always be async if the head block is async
20+
b.arrow([b.id('$$payload')], block, context.state.analysis.has_blocking_await)
21+
)
22+
)
1523
);
1624
}

packages/svelte/src/compiler/phases/3-transform/server/visitors/TitleElement.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,30 @@ export function TitleElement(node, context) {
1313
process_children(node.fragment.nodes, { ...context, state: { ...context.state, template } });
1414
template.push(b.literal('</title>'));
1515

16-
if (!node.metadata.has_await) {
17-
context.state.init.push(...build_template(template, b.id('$$payload.title.value'), '='));
18-
} else {
19-
const async_template = b.thunk(
20-
// TODO I'm sure there is a better way to do this
21-
b.block([
22-
b.let('title'),
23-
...build_template(template, b.id('title'), '='),
24-
b.return(b.id('title'))
25-
]),
26-
true
27-
);
28-
context.state.init.push(
29-
b.stmt(b.assignment('=', b.id('$$payload.title.value'), b.call(async_template)))
30-
);
31-
}
16+
context.state.init.push(
17+
b.stmt(
18+
b.call(
19+
'$$payload.child',
20+
// this nonsense is necessary so that the write to the title is as tightly scoped to a specific location
21+
// in the async tree as possible. This lets us use `get_path` to compare this assignment to other assignments
22+
// so that we can overwrite earlier assignments with later ones.
23+
b.arrow(
24+
[b.id('$$payload')],
25+
b.block([
26+
b.const('path', b.call('$$payload.get_path')),
27+
b.let('title'),
28+
...build_template(template, b.id('title'), '='),
29+
b.stmt(
30+
b.assignment(
31+
'=',
32+
b.id('$$payload.global.head.title'),
33+
b.object([b.init('path', b.id('path')), b.init('value', b.id('title'))])
34+
)
35+
)
36+
]),
37+
node.metadata.has_await
38+
)
39+
)
40+
)
41+
);
3242
}

packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export function build_inline_component(node, expression, context) {
238238
b.call(
239239
'$$payload.child',
240240
b.arrow(
241-
[b.object_pattern([b.init('$$payload', b.id('$$payload'))])],
241+
[b.id('$$payload')],
242242
b.block(block.body),
243243
context.state.analysis.has_blocking_await
244244
)

packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/utils.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function is_statement(node) {
9999
* @param {AssignmentOperator | 'push'} operator
100100
* @returns {Statement[]}
101101
*/
102-
export function build_template(template, out = b.id('$$payload.out'), operator = 'push') {
102+
export function build_template(template, out = b.id('$$payload'), operator = 'push') {
103103
/** @type {string[]} */
104104
let strings = [];
105105

@@ -264,10 +264,5 @@ export function build_getter(node, state) {
264264
* @returns {Statement}
265265
*/
266266
export function wrap_in_child_payload(body, async) {
267-
return b.stmt(
268-
b.call(
269-
'$$payload.child',
270-
b.arrow([b.object_pattern([b.init('$$payload', b.id('$$payload'))])], body, async)
271-
)
272-
);
267+
return b.stmt(b.call('$$payload.child', b.arrow([b.id('$$payload')], body, async)));
273268
}

0 commit comments

Comments
 (0)