Skip to content

Commit 02c2ca4

Browse files
committedJan 21, 2025

File tree

2 files changed

+18
-47
lines changed

2 files changed

+18
-47
lines changed
 

‎packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,6 @@ export function client_component(analysis, options) {
354354
const push_args = [b.id('$$props'), b.literal(analysis.runes)];
355355
if (dev) push_args.push(b.id(analysis.name));
356356

357-
if (analysis.is_async) {
358-
const body = /** @type {ESTree.FunctionDeclaration} */ (template.body[0]);
359-
body.body.body.unshift(...instance.body);
360-
instance.body.length = 0;
361-
}
362-
363357
let component_block = b.block([
364358
...store_setup,
365359
...legacy_reactive_declarations,
@@ -372,6 +366,24 @@ export function client_component(analysis, options) {
372366
.../** @type {ESTree.Statement[]} */ (template.body)
373367
]);
374368

369+
if (analysis.is_async) {
370+
const body = b.function_declaration(
371+
b.id('$$body'),
372+
[b.id('$$anchor'), b.id('$$props')],
373+
component_block
374+
);
375+
body.async = true;
376+
377+
state.hoisted.push(body);
378+
379+
component_block = b.block([
380+
b.var('fragment', b.call('$.comment')),
381+
b.var('node', b.call('$.first_child', b.id('fragment'))),
382+
b.stmt(b.call(body.id, b.id('node'), b.id('$$props'))),
383+
b.stmt(b.call('$.append', b.id('$$anchor'), b.id('fragment')))
384+
]);
385+
}
386+
375387
if (!analysis.runes) {
376388
// Bind static exports to props so that people can access them with bind:x
377389
for (const { name, alias } of analysis.exports) {

‎packages/svelte/src/compiler/phases/3-transform/client/visitors/Fragment.js

-41
Original file line numberDiff line numberDiff line change
@@ -199,47 +199,6 @@ export function Fragment(node, context) {
199199
const async =
200200
state.metadata.async.length > 0 || (state.analysis.is_async && context.path.length === 0);
201201

202-
if (async) {
203-
// TODO need to create bookends for hydration to work
204-
return b.block([
205-
b.function_declaration(
206-
b.id('$$body'),
207-
[b.id('$$anchor')],
208-
b.block([
209-
b.var(
210-
b.array_pattern(state.metadata.async.map(({ id }) => id)),
211-
b.call(
212-
b.member(
213-
b.await(
214-
b.call(
215-
'$.suspend',
216-
b.call(
217-
'Promise.all',
218-
b.array(
219-
state.metadata.async.map(({ expression }) =>
220-
b.call('$.async_derived', b.thunk(expression, true))
221-
)
222-
)
223-
)
224-
)
225-
),
226-
'exit'
227-
)
228-
)
229-
),
230-
...body,
231-
b.stmt(b.call('$.exit'))
232-
]),
233-
true
234-
),
235-
236-
b.var('fragment', b.call('$.comment')),
237-
b.var('node', b.call('$.first_child', b.id('fragment'))),
238-
b.stmt(b.call(b.id('$$body'), b.id('node'))),
239-
b.stmt(b.call('$.append', b.id('$$anchor'), b.id('fragment')))
240-
]);
241-
}
242-
243202
return b.block(body);
244203
}
245204

0 commit comments

Comments
 (0)
Please sign in to comment.