Skip to content

Commit ea0e269

Browse files
committed
fix settled when awaits occur inside pending boundary
1 parent 5fda011 commit ea0e269

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @import { Effect, TemplateNode, } from '#client' */
22

3-
import { BOUNDARY_EFFECT, EFFECT_PRESERVED, EFFECT_TRANSPARENT } from '#client/constants';
3+
import { BOUNDARY_EFFECT, EFFECT_PRESERVED, EFFECT_TRANSPARENT, INERT } from '#client/constants';
44
import { component_context, set_component_context } from '../../context.js';
55
import { invoke_error_boundary } from '../../error-handling.js';
66
import { block, branch, destroy_effect, pause_effect } from '../../reactivity/effects.js';
@@ -151,6 +151,14 @@ export class Boundary {
151151
return !!this.#props.pending;
152152
}
153153

154+
is_pending() {
155+
if (!this.ran && this.#props.pending) {
156+
return true;
157+
}
158+
159+
return this.#pending_effect !== null && (this.#pending_effect.f & INERT) === 0;
160+
}
161+
154162
/**
155163
* @param {() => Effect | null} fn
156164
*/

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export class Batch {
5151
/** @type {Effect[]} */
5252
async_effects = [];
5353

54+
/** @type {Effect[]} */
55+
boundary_async_effects = [];
56+
5457
/** @type {Effect[]} */
5558
render_effects = [];
5659

@@ -188,7 +191,12 @@ export class Batch {
188191
update_effect(effect);
189192
}
190193

194+
for (const effect of this.boundary_async_effects) {
195+
update_effect(effect);
196+
}
197+
191198
this.async_effects = [];
199+
this.boundary_async_effects = [];
192200
}
193201

194202
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function async_derived(fn, location) {
132132
prev = promise;
133133

134134
var batch = /** @type {Batch} */ (current_batch);
135-
var ran = boundary.ran;
135+
var ran = !boundary.is_pending();
136136

137137
if (should_suspend) {
138138
(ran ? batch : boundary).increment();

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,11 @@ export function process_effects(batch, root) {
654654

655655
if (!skip && effect.fn !== null) {
656656
if ((flags & EFFECT_ASYNC) !== 0) {
657+
const boundary = effect.b;
658+
657659
if (check_dirtiness(effect)) {
658-
batch.async_effects.push(effect);
660+
var effects = boundary?.is_pending() ? batch.boundary_async_effects : batch.async_effects;
661+
effects.push(effect);
659662
}
660663
} else if ((flags & BLOCK_EFFECT) !== 0) {
661664
if (check_dirtiness(effect)) {

packages/svelte/tests/runtime-runes/samples/async-abort-signal/_config.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { flushSync, tick } from 'svelte';
1+
import { settled } from 'svelte';
22
import { test } from '../../test';
33

44
export default test({
@@ -9,22 +9,17 @@ export default test({
99

1010
const [reset, resolve] = target.querySelectorAll('button');
1111

12-
flushSync(() => reset.click());
13-
await Promise.resolve();
14-
await Promise.resolve();
15-
await Promise.resolve();
16-
await Promise.resolve();
17-
await Promise.resolve();
18-
await Promise.resolve();
19-
await tick();
12+
reset.click();
13+
await settled();
2014
assert.deepEqual(logs, ['aborted']);
2115

22-
flushSync(() => resolve.click());
16+
resolve.click();
17+
await Promise.resolve();
18+
await Promise.resolve();
2319
await Promise.resolve();
2420
await Promise.resolve();
2521
await Promise.resolve();
2622
await Promise.resolve();
27-
await tick();
2823
assert.htmlEqual(
2924
target.innerHTML,
3025
`

0 commit comments

Comments
 (0)