Skip to content

Commit 7f0072b

Browse files
committed
tidy
1 parent c8e47cc commit 7f0072b

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
/** @import { TemplateNode, Value } from '#client' */
1+
/** @import { Effect, TemplateNode, Value } from '#client' */
2+
import { DESTROYED } from '#client/constants';
23
import { async_derived } from '../../reactivity/deriveds.js';
4+
import { active_effect } from '../../runtime.js';
35
import { capture, get_pending_boundary } from './boundary.js';
46

57
/**
@@ -10,12 +12,16 @@ import { capture, get_pending_boundary } from './boundary.js';
1012
export function async(node, expressions, fn) {
1113
// TODO handle hydration
1214

15+
var parent = /** @type {Effect} */ (active_effect);
16+
1317
var restore = capture();
1418
var boundary = get_pending_boundary();
1519

1620
boundary.increment();
1721

1822
Promise.all(expressions.map((fn) => async_derived(fn))).then((result) => {
23+
if ((parent.f & DESTROYED) !== 0) return;
24+
1925
restore();
2026
fn(node, ...result);
2127

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ import {
3434
EFFECT_PRESERVED,
3535
STALE_REACTION
3636
} from '#client/constants';
37-
import { set } from './sources.js';
3837
import * as e from '../errors.js';
3938
import { DEV } from 'esm-env';
4039
import { define_property } from '../../shared/utils.js';
4140
import { get_next_sibling } from '../dom/operations.js';
4241
import { async_derived, derived } from './deriveds.js';
43-
import { capture, get_pending_boundary } from '../dom/blocks/boundary.js';
42+
import { capture } from '../dom/blocks/boundary.js';
4443
import { component_context, dev_current_component_function } from '../context.js';
45-
import { current_batch, Batch } from './batch.js';
44+
import { Batch } from './batch.js';
4645

4746
/**
4847
* @param {'$effect' | '$effect.pre' | '$inspect'} rune
@@ -343,24 +342,13 @@ export function template_effect(fn, sync = [], async = [], d = derived) {
343342
var parent = /** @type {Effect} */ (active_effect);
344343

345344
if (async.length > 0) {
346-
var batch = /** @type {Batch} */ (current_batch);
347345
var restore = capture();
348346

349-
var boundary = get_pending_boundary();
350-
var ran = boundary.ran;
351-
352347
Promise.all(async.map((expression) => async_derived(expression))).then((result) => {
353-
restore();
354-
355-
if ((parent.f & DESTROYED) !== 0) {
356-
return;
357-
}
358-
359-
var effect = create_template_effect(fn, [...sync.map(d), ...result]);
348+
if ((parent.f & DESTROYED) !== 0) return;
360349

361-
if (ran) batch.restore();
362-
schedule_effect(effect);
363-
if (ran) batch.flush();
350+
restore();
351+
create_template_effect(fn, [...sync.map(d), ...result]);
364352
});
365353
} else {
366354
create_template_effect(fn, sync.map(d));
@@ -380,7 +368,7 @@ function create_template_effect(fn, deriveds) {
380368
});
381369
}
382370

383-
return create_effect(RENDER_EFFECT, effect, true);
371+
create_effect(RENDER_EFFECT, effect, true);
384372
}
385373

386374
/**

0 commit comments

Comments
 (0)