Skip to content

Commit 80b713a

Browse files
committed
abort component if already destroyed
1 parent 0a5628f commit 80b713a

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ export function client_component(analysis, options) {
363363
.../** @type {ESTree.Statement[]} */ (instance.body),
364364
analysis.runes || !analysis.needs_context
365365
? b.empty
366-
: b.stmt(b.call('$.init', analysis.immutable ? b.true : undefined)),
367-
.../** @type {ESTree.Statement[]} */ (template.body)
366+
: b.stmt(b.call('$.init', analysis.immutable ? b.true : undefined))
368367
]);
369368

370369
if (analysis.instance.is_async) {
@@ -374,6 +373,8 @@ export function client_component(analysis, options) {
374373
b.block([
375374
b.var('$$unsuspend', b.call('$.suspend')),
376375
...component_block.body,
376+
b.if(b.call('$.aborted'), b.return()),
377+
.../** @type {ESTree.Statement[]} */ (template.body),
377378
b.stmt(b.call('$$unsuspend'))
378379
])
379380
);
@@ -387,6 +388,8 @@ export function client_component(analysis, options) {
387388
b.stmt(b.call(body.id, b.id('node'), b.id('$$props'))),
388389
b.stmt(b.call('$.append', b.id('$$anchor'), b.id('fragment')))
389390
]);
391+
} else {
392+
component_block.body.push(.../** @type {ESTree.Statement[]} */ (template.body));
390393
}
391394

392395
if (!analysis.runes) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export {
101101
} from './dom/template.js';
102102
export { async_derived, derived, derived_safe_equal } from './reactivity/deriveds.js';
103103
export {
104+
aborted,
104105
effect_tracking,
105106
effect_root,
106107
legacy_pre_effect,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,8 @@ function resume_children(effect, local) {
659659
}
660660
}
661661
}
662+
663+
export function aborted() {
664+
var effect = /** @type {Effect} */ (active_effect);
665+
return (effect.f & DESTROYED) !== 0;
666+
}

0 commit comments

Comments
 (0)