Skip to content

Commit 3dd1d30

Browse files
committed
remove script_suspend in favour of component-level suspending
1 parent 3893489 commit 3dd1d30

File tree

4 files changed

+10
-41
lines changed

4 files changed

+10
-41
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,11 @@ export function client_component(analysis, options) {
371371
const body = b.function_declaration(
372372
b.id('$$body'),
373373
[b.id('$$anchor'), b.id('$$props')],
374-
b.block([...component_block.body, b.stmt(b.call('$.exit'))])
374+
b.block([
375+
b.var('$$unsuspend', b.call('$.suspend')),
376+
...component_block.body,
377+
b.stmt(b.call('$$unsuspend'))
378+
])
375379
);
376380
body.async = true;
377381

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/** @import { AwaitExpression, Expression } from 'estree' */
22
/** @import { Context } from '../types' */
33
import * as b from '../../../../utils/builders.js';
4-
import { get_rune } from '../../../scope.js';
54

65
/**
76
* @param {AwaitExpression} node
@@ -14,22 +13,9 @@ export function AwaitExpression(node, context) {
1413
return context.next();
1514
}
1615

17-
const inside_derived = context.path.some(
18-
(n) =>
19-
n.type === 'VariableDeclaration' &&
20-
n.declarations.some(
21-
(d) =>
22-
d.init?.type === 'CallExpression' && get_rune(d.init, context.state.scope) === '$derived'
23-
)
24-
);
25-
26-
const expression = b.call(
16+
return b.call(
2717
b.await(
2818
b.call('$.save', node.argument && /** @type {Expression} */ (context.visit(node.argument)))
2919
)
3020
);
31-
32-
return inside_derived
33-
? expression
34-
: b.await(b.call('$.script_suspend', b.arrow([], expression, true)));
3521
}

packages/svelte/src/internal/client/dom/blocks/boundary.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -243,23 +243,18 @@ export function boundary(node, props, boundary_fn) {
243243
}
244244
}
245245

246-
// TODO separate this stuff out — suspending and context preservation should
247-
// be distinct concepts
248-
249246
export function capture() {
250247
var previous_effect = active_effect;
251248
var previous_reaction = active_reaction;
252249
var previous_component_context = component_context;
253250

254-
return function restore(should_exit = true) {
251+
return function restore() {
255252
set_active_effect(previous_effect);
256253
set_active_reaction(previous_reaction);
257254
set_component_context(previous_component_context);
258255

259256
// prevent the active effect from outstaying its welcome
260-
if (should_exit) {
261-
queue_post_micro_task(exit);
262-
}
257+
queue_post_micro_task(exit);
263258
};
264259
}
265260

@@ -295,22 +290,6 @@ export function suspend() {
295290
};
296291
}
297292

298-
/**
299-
* @template T
300-
* @param {() => Promise<T>} fn
301-
*/
302-
export async function script_suspend(fn) {
303-
const restore = capture();
304-
const unsuspend = suspend();
305-
try {
306-
exit();
307-
return await fn();
308-
} finally {
309-
restore(false);
310-
unsuspend();
311-
}
312-
}
313-
314293
/**
315294
* @template T
316295
* @param {Promise<T>} promise
@@ -326,7 +305,7 @@ export async function save(promise) {
326305
};
327306
}
328307

329-
export function exit() {
308+
function exit() {
330309
set_active_effect(null);
331310
set_active_reaction(null);
332311
set_component_context(null);

packages/svelte/src/internal/client/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export {
130130
update_store,
131131
mark_store_binding
132132
} from './reactivity/store.js';
133-
export { boundary, exit, save, suspend, script_suspend } from './dom/blocks/boundary.js';
133+
export { boundary, save, suspend } from './dom/blocks/boundary.js';
134134
export { set_text } from './render.js';
135135
export {
136136
get,

0 commit comments

Comments
 (0)