Skip to content

Commit f3fc443

Browse files
committed
WIP
1 parent 65f5970 commit f3fc443

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ export function client_component(analysis, options) {
384384
.../** @type {ESTree.Statement[]} */ (template.body)
385385
]);
386386

387-
component_block.body.push(b.stmt(b.call(`$.async_body`, b.arrow([], body, true))));
387+
component_block.body.push(
388+
b.stmt(b.call(`$.async_body`, b.id('$$anchor'), b.arrow([b.id('$$anchor')], body, true)))
389+
);
388390
} else {
389391
component_block.body.push(
390392
...state.instance_level_snippets,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ export function Fragment(node, context) {
177177
}
178178

179179
if (has_await) {
180-
return b.block([b.stmt(b.call('$.async_body', b.arrow([], b.block(body), true)))]);
180+
return b.block([
181+
b.stmt(
182+
b.call('$.async_body', b.id('$$anchor'), b.arrow([b.id('$$anchor')], b.block(body), true))
183+
)
184+
]);
181185
} else {
182186
return b.block(body);
183187
}

packages/svelte/src/internal/client/reactivity/async.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/** @import { Effect, Value } from '#client' */
2-
1+
/** @import { Effect, TemplateNode, Value } from '#client' */
32
import { DESTROYED } from '#client/constants';
43
import { DEV } from 'esm-env';
54
import { component_context, is_runes, set_component_context } from '../context.js';
@@ -28,6 +27,7 @@ import {
2827
set_hydrating,
2928
skip_nodes
3029
} from '../dom/hydration.js';
30+
import { create_text } from '../dom/operations.js';
3131

3232
/**
3333
*
@@ -197,9 +197,10 @@ export function unset_context() {
197197
}
198198

199199
/**
200-
* @param {() => Promise<void>} fn
200+
* @param {TemplateNode} anchor
201+
* @param {(target: TemplateNode) => Promise<void>} fn
201202
*/
202-
export async function async_body(fn) {
203+
export async function async_body(anchor, fn) {
203204
var boundary = get_boundary();
204205
var batch = /** @type {Batch} */ (current_batch);
205206
var pending = boundary.is_pending();
@@ -217,8 +218,11 @@ export async function async_body(fn) {
217218
next_hydrate_node = skip_nodes(false);
218219
}
219220

221+
var target = create_text();
222+
anchor.before(target);
223+
220224
try {
221-
var promise = fn();
225+
var promise = fn(target);
222226
} finally {
223227
if (next_hydrate_node) {
224228
set_hydrate_node(next_hydrate_node);
@@ -228,6 +232,7 @@ export async function async_body(fn) {
228232

229233
try {
230234
await promise;
235+
target.remove();
231236
} catch (error) {
232237
if (!aborted(active)) {
233238
invoke_error_boundary(error, active);

0 commit comments

Comments
 (0)