Skip to content

Commit ed17212

Browse files
committed
fix
1 parent fc18e26 commit ed17212

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,27 @@ export function async(node, expressions, fn) {
1818

1919
var restore = capture();
2020

21-
Promise.all(expressions.map((fn) => async_derived(fn))).then((result) => {
22-
restore();
23-
fn(node, ...result);
21+
let boundary = effect.b;
22+
23+
while (boundary !== null && !boundary.has_pending_snippet()) {
24+
boundary = boundary.parent;
25+
}
26+
27+
if (boundary === null) {
28+
throw new Error('TODO cannot create async derived outside a boundary with a pending snippet');
29+
}
30+
31+
boundary.increment();
2432

25-
// TODO is this necessary?
33+
Promise.all(expressions.map((fn) => async_derived(fn))).then((result) => {
2634
batch.run(() => {
35+
restore();
36+
fn(node, ...result);
37+
38+
// TODO is this necessary?
2739
schedule_effect(effect);
2840
});
41+
42+
boundary.decrement();
2943
});
3044
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,28 @@ export class Boundary {
119119
return branch(() => this.#children(this.#anchor));
120120
});
121121

122-
if (this.#pending_count === 0) {
122+
if (this.#pending_count > 0) {
123+
this.#show_pending_snippet();
124+
} else {
123125
pause_effect(/** @type {Effect} */ (this.#pending_effect), () => {
124126
this.#pending_effect = null;
125127
});
128+
this.ran = true;
126129
}
127130
});
128131
} else {
129132
this.#main_effect = branch(() => children(this.#anchor));
130133

131134
if (this.#pending_count > 0) {
132135
this.#show_pending_snippet();
136+
} else {
137+
this.ran = true;
133138
}
134139
}
135140

136141
reset_is_throwing_error();
137142
}, flags);
138143

139-
this.ran = true;
140-
141144
if (hydrating) {
142145
this.#anchor = hydrate_node;
143146
}
@@ -189,6 +192,8 @@ export class Boundary {
189192
}
190193

191194
commit() {
195+
this.ran = true;
196+
192197
if (this.#pending_effect) {
193198
pause_effect(this.#pending_effect, () => {
194199
this.#pending_effect = null;
@@ -242,10 +247,10 @@ export class Boundary {
242247
}
243248
});
244249

245-
this.ran = true;
246-
247250
if (this.#pending_count > 0) {
248251
this.#show_pending_snippet();
252+
} else {
253+
this.ran = true;
249254
}
250255
};
251256

0 commit comments

Comments
 (0)