use fragment as async hoist boundary

pull/16757/head
Rich Harris 1 week ago
parent 127c5a73cb
commit 48b766cc46

@ -2,6 +2,7 @@
/** @import { Context } from '../types' */ /** @import { Context } from '../types' */
import * as e from '../../../errors.js'; import * as e from '../../../errors.js';
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import { filename } from '../../../state.js';
/** /**
* @param {AwaitExpression} node * @param {AwaitExpression} node
@ -17,14 +18,12 @@ export function AwaitExpression(node, context) {
context.state.fragment.metadata.has_await = true; context.state.fragment.metadata.has_await = true;
} }
if (context.state.async_hoist_boundary) { if (context.state.fragment) {
const len = context.state.async_hoist_boundary.metadata.hoisted_promises.promises.push( const len = context.state.fragment.metadata.hoisted_promises.promises.push(node.argument);
node.argument
);
context.state.analysis.hoisted_promises.set( context.state.analysis.hoisted_promises.set(
node.argument, node.argument,
b.member( b.member(
b.id(context.state.async_hoist_boundary.metadata.hoisted_promises.name), b.id(context.state.fragment.metadata.hoisted_promises.name),
b.literal(len - 1), b.literal(len - 1),
true true
) )

@ -192,6 +192,15 @@ export function RegularElement(node, context) {
) )
); );
} else { } else {
if (node.fragment.metadata.hoisted_promises.promises.length > 0) {
state.template.push(
b.const(
node.fragment.metadata.hoisted_promises.name,
b.array(node.fragment.metadata.hoisted_promises.promises)
)
);
}
process_children(trimmed, { ...context, state }); process_children(trimmed, { ...context, state });
} }

@ -8,6 +8,15 @@ import { process_children, build_template, call_child_payload } from './shared/u
* @param {ComponentContext} context * @param {ComponentContext} context
*/ */
export function TitleElement(node, context) { export function TitleElement(node, context) {
if (node.fragment.metadata.hoisted_promises.promises.length > 0) {
context.state.init.push(
b.const(
node.fragment.metadata.hoisted_promises.name,
b.array(node.fragment.metadata.hoisted_promises.promises)
)
);
}
// title is guaranteed to contain only text/expression tag children // title is guaranteed to contain only text/expression tag children
const template = [b.literal('<title>')]; const template = [b.literal('<title>')];
process_children(node.fragment.nodes, { ...context, state: { ...context.state, template } }); process_children(node.fragment.nodes, { ...context, state: { ...context.state, template } });

Loading…
Cancel
Save