fix: only create async functions in SSR output when necessary (#17593)

* fix: only create async functions in SSR output when necessary

* actually...

* simplify generated code a bit more

* simplify
fix-15339
Rich Harris 6 days ago committed by 7nik
parent 16ea0cee92
commit b2191c3657

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: only create async functions in SSR output when necessary

@ -70,8 +70,7 @@ export function RegularElement(node, context) {
if (optimiser.expressions.length > 0) {
context.state.template.push(
create_child_block(
b.block([optimiser.apply(), ...state.init, ...build_template(state.template)]),
true
b.block([optimiser.apply(), ...state.init, ...build_template(state.template)])
)
);
} else {
@ -133,7 +132,7 @@ export function RegularElement(node, context) {
if (optimiser.expressions.length > 0) {
context.state.template.push(
create_child_block(b.block([optimiser.apply(), ...state.init, statement]), true)
create_child_block(b.block([optimiser.apply(), ...state.init, statement]))
);
} else {
context.state.template.push(...state.init, statement);
@ -186,7 +185,7 @@ export function RegularElement(node, context) {
if (optimiser.expressions.length > 0) {
context.state.template.push(
create_child_block(b.block([optimiser.apply(), ...state.init, statement]), true)
create_child_block(b.block([optimiser.apply(), ...state.init, statement]))
);
} else {
context.state.template.push(...state.init, statement);
@ -236,18 +235,19 @@ export function RegularElement(node, context) {
}
if (optimiser.is_async()) {
let statement = create_child_block(
b.block([optimiser.apply(), ...state.init, ...build_template(state.template)]),
true
);
let statements = [...state.init, ...build_template(state.template)];
if (optimiser.has_await) {
statements = [create_child_block(b.block([optimiser.apply(), ...statements]))];
}
const blockers = optimiser.blockers();
if (blockers.elements.length > 0) {
statement = create_async_block(b.block([statement]), blockers, false, false);
statements = [create_async_block(b.block(statements), blockers, false, false)];
}
context.state.template.push(statement);
context.state.template.push(...statements);
} else {
context.state.init.push(...state.init);
context.state.template.push(...state.template);

@ -79,7 +79,7 @@ export function SvelteElement(node, context) {
);
if (optimiser.expressions.length > 0) {
statement = create_child_block(b.block([optimiser.apply(), statement]), true);
statement = create_child_block(b.block([optimiser.apply(), statement]));
}
statements.push(statement);

@ -264,11 +264,10 @@ export function build_getter(node, state) {
/**
* Creates a `$$renderer.child(...)` expression statement
* @param {BlockStatement | Expression} body
* @param {boolean} async
* @returns {Statement}
*/
export function create_child_block(body, async) {
return b.stmt(b.call('$$renderer.child', b.arrow([b.id('$$renderer')], body, async)));
export function create_child_block(body) {
return b.stmt(b.call('$$renderer.child', b.arrow([b.id('$$renderer')], body, true)));
}
/**

Loading…
Cancel
Save