Skip to content

Commit 4d8432a

Browse files
committed
fix
1 parent 12188f3 commit 4d8432a

File tree

3 files changed

+17
-12
lines changed
  • packages/svelte

3 files changed

+17
-12
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ export function async(node, expressions, fn) {
1414
boundary.update_pending_count(1);
1515

1616
flatten([], expressions, (values) => {
17-
// get values eagerly to avoid creating blocks if they reject
18-
for (const d of values) get(d);
17+
try {
18+
// get values eagerly to avoid creating blocks if they reject
19+
for (const d of values) get(d);
1920

20-
fn(node, ...values);
21-
boundary.update_pending_count(-1);
21+
fn(node, ...values);
22+
} finally {
23+
boundary.update_pending_count(-1);
24+
}
2225
});
2326
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ export function flatten(sync, async, fn) {
2727

2828
Promise.all(async.map((expression) => async_derived(expression)))
2929
.then((result) => {
30-
if ((parent.f & DESTROYED) !== 0) return;
31-
3230
batch?.activate();
3331

3432
restore();
3533

3634
try {
3735
fn([...sync.map(d), ...result]);
3836
} catch (error) {
39-
invoke_error_boundary(error, parent);
37+
// ignore errors in blocks that have already been destroyed
38+
if ((parent.f & DESTROYED) === 0) {
39+
invoke_error_boundary(error, parent);
40+
}
4041
}
4142

4243
batch?.deactivate();

packages/svelte/tests/runtime-runes/samples/async-block-reject-each-during-init/_config.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@ import { tick } from 'svelte';
22
import { test } from '../../test';
33

44
export default test({
5-
async test({ assert, target }) {
6-
const [increment, shift] = target.querySelectorAll('button');
5+
async test({ assert, target, errors }) {
6+
const [increment, resolve, reject] = target.querySelectorAll('button');
77

88
increment.click();
99
await tick();
1010

11-
shift.click();
11+
reject.click();
1212
await tick();
1313

14-
shift.click();
14+
resolve.click();
1515
await tick();
1616

1717
assert.htmlEqual(
1818
target.innerHTML,
1919
`
2020
<button>increment</button>
21-
<button>shift</button>
21+
<button>resolve</button>
22+
<button>reject</button>
2223
<p>false</p>
2324
<p>1</p>
2425
`

0 commit comments

Comments
 (0)