pull/16762/head
S. Elliott Johnson 4 weeks ago
parent d6c7f58e69
commit f1c0634733

@ -426,7 +426,6 @@ function open(parser) {
body: create_fragment(),
metadata: {
can_hoist: false,
has_await: false,
sites: new Set()
}
});

@ -538,7 +538,7 @@ export function analyze_component(root, source, options) {
snippet_renderers: new Map(),
snippets: new Set(),
async_deriveds: new Set(),
has_blocking_await: false,
suspends_without_fallback: false,
hoisted_promises: new Map()
};

@ -48,11 +48,9 @@ export function AwaitExpression(node, context) {
if (!context.state.analysis.runes) {
e.legacy_await_invalid(node);
}
}
// the await will only block if there's no `pending` snippet
context.state.analysis.has_blocking_await ||=
suspend && !context.state.boundary?.metadata.pending;
context.state.analysis.suspends_without_fallback ||= !context.state.boundary?.metadata.pending;
}
context.next();
}

@ -247,7 +247,7 @@ export function server_component(analysis, options) {
.../** @type {Statement[]} */ (instance.body),
.../** @type {Statement[]} */ (template.body)
]),
analysis.has_blocking_await
analysis.suspends_without_fallback
)
)
)

@ -164,7 +164,7 @@ export function RegularElement(node, context) {
b.arrow(
[b.id('$$payload')],
b.block([...inner_state.init, ...build_template(inner_state.template)]),
context.state.analysis.has_blocking_await
context.state.analysis.suspends_without_fallback
)
)
)
@ -208,7 +208,7 @@ export function RegularElement(node, context) {
// TODO this will always produce correct results (because it will produce an async function if the surrounding component is async)
// but it will false-positive and create unnecessary async functions (eg. when the component is async but the select element is not)
// we could probably optimize by checking if the select element is async. Might be worth it.
context.state.analysis.has_blocking_await
context.state.analysis.suspends_without_fallback
)
);
}

@ -17,7 +17,7 @@ export function SvelteHead(node, context) {
b.id('$$payload'),
// same thing as elsewhere; this will create more async functions than necessary but should never be _wrong_
// because the component rendering this head block will always be async if the head block is async
b.arrow([b.id('$$payload')], block, context.state.analysis.has_blocking_await)
b.arrow([b.id('$$payload')], block, context.state.analysis.suspends_without_fallback)
)
)
);

@ -240,7 +240,7 @@ export function build_inline_component(node, expression, context) {
b.arrow(
[b.id('$$payload')],
b.block(block.body),
context.state.analysis.has_blocking_await
context.state.analysis.suspends_without_fallback
)
)
)

@ -108,7 +108,7 @@ export interface ComponentAnalysis extends Analysis {
*/
snippets: Set<AST.SnippetBlock>;
/** Whether the component uses `await` in a context that would require an `await` on the server. */
has_blocking_await: boolean;
suspends_without_fallback: boolean;
hoisted_promises: Map<Expression, MemberExpression>;
}

Loading…
Cancel
Save