Commit 6557a0a
fix: run effects in pending snippets (#17719)
Boundaries are buggy: if the `pending` snippet contains state, changes
to that state [won't cause
updates](https://svelte.dev/playground/hello-world?version=5.51.2#H4sIAAAAAAAAE22SQW-DMAyF_0qUTSpoE92uFJh223Hate0hJWaNliZRYsoqxH9fQtJW6noD-33Pz4aRKnYAWtIPkFKTQVvJSQZcIPCcPtNOSHC0XI8UTyboQsHXE_VuTOGOIDHUdszBvXqrFYJCb0Mr11phsNmoDUpAYsFpeQTrSE3W25Uv-0bXqxaFVsT0bp8dmewhJ2PobNB7OSQcOrAWuKc-rT4IB8UgcP91dsvyVZRf_IvZK8tJ3VzoInXTiCuDvVVXlYkT5u50k9DtRYfZJd11XGq8FSlKAsPOre4V-uSPDhlC9hIE1fJ6GFXtekRvrlUrRftTjzF25J5q8jrN9xOqtXDwhw14RO7jc5bIzI-3-vihyp3358yeZmFlmpENTGD8CIu0GV_kU7U0TdxmfHBKGON3MqC4UN9ZPsVDBHzOe1bjuEzaad7230j_nyD8Ii3R9jBt_RsTchCK07Jj0sH0B6hNF6aqAgAA):
```svelte
<script>
let resolvers = [];
function push(value) {
const deferred = Promise.withResolvers();
resolvers.push(() => deferred.resolve(value));
return deferred.promise;
}
function shift() {
resolvers.shift()?.();
}
let count = $state(0);
</script>
<button onclick={() => count += 1}>
increment
</button>
<button onclick={shift}>
shift
</button>
<svelte:boundary>
<p>{await push('resolved')}</p>
{#snippet pending()}
<p>{count}</p>
{/snippet}
</svelte:boundary>
```
The issue is that the boundary's `this.#effect` has the
`BOUNDARY_EFFECT` flag, and `this.#pending_effect` is a child thereof.
Instead, `this.#main_effect` should have the flag. (It turns out
`this.#failed_effect` _also_ needs the flag, because errors that occur
in a `failed` snippet cause the boundary to re-render in its `failed`
state, which I found somewhat confusing to be honest. Probably the right
choice though.)
I was able to simplify the code a bit, too.
~~(Actually now that I think about it do we need `this.#effect` at all?
Will check.)~~
### Before submitting the PR, please make sure you do the following
- [x] It's really useful if your PR references an issue where it is
discussed ahead of time. In many cases, features are absent for a
reason. For large changes, please create an RFC:
https://github.com/sveltejs/rfcs
- [x] Prefix your PR title with `feat:`, `fix:`, `chore:`, or `docs:`.
- [x] This message body should clearly illustrate what problems it
solves.
- [x] Ideally, include a test that fails without this PR but passes with
it.
- [x] If this PR changes code within `packages/svelte/src`, add a
changeset (`npx changeset`).
### Tests and linting
- [x] Run the tests with `pnpm test` and lint the project with `pnpm
lint`
---------
Co-authored-by: Simon H <[email protected]>1 parent ff70ab1 commit 6557a0a
5 files changed
Lines changed: 139 additions & 94 deletions
File tree
- .changeset
- packages/svelte
- src/internal/client
- dom/blocks
- reactivity
- tests/runtime-runes/samples/async-boundary-pending-live
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 55 additions & 87 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
53 | 52 | | |
54 | 53 | | |
55 | 54 | | |
56 | | - | |
| 55 | + | |
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
| |||
98 | 97 | | |
99 | 98 | | |
100 | 99 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | 100 | | |
105 | 101 | | |
106 | 102 | | |
107 | 103 | | |
108 | | - | |
109 | | - | |
110 | 104 | | |
111 | 105 | | |
112 | 106 | | |
| |||
142 | 136 | | |
143 | 137 | | |
144 | 138 | | |
145 | | - | |
146 | 139 | | |
147 | | - | |
| 140 | + | |
| 141 | + | |
148 | 142 | | |
149 | | - | |
| 143 | + | |
| 144 | + | |
150 | 145 | | |
151 | | - | |
152 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
153 | 150 | | |
| 151 | + | |
154 | 152 | | |
155 | | - | |
| 153 | + | |
156 | 154 | | |
157 | 155 | | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
| 156 | + | |
163 | 157 | | |
164 | 158 | | |
165 | 159 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | 160 | | |
171 | 161 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
| 162 | + | |
185 | 163 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | 164 | | |
191 | 165 | | |
192 | 166 | | |
| |||
206 | 180 | | |
207 | 181 | | |
208 | 182 | | |
| 183 | + | |
209 | 184 | | |
210 | 185 | | |
211 | 186 | | |
212 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
213 | 191 | | |
214 | 192 | | |
215 | 193 | | |
216 | 194 | | |
217 | 195 | | |
218 | 196 | | |
219 | | - | |
220 | | - | |
221 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
222 | 201 | | |
223 | 202 | | |
224 | 203 | | |
| |||
228 | 207 | | |
229 | 208 | | |
230 | 209 | | |
231 | | - | |
232 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
233 | 219 | | |
234 | | - | |
235 | | - | |
236 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
237 | 223 | | |
238 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
239 | 231 | | |
240 | | - | |
241 | | - | |
242 | 232 | | |
243 | 233 | | |
244 | 234 | | |
| |||
262 | 252 | | |
263 | 253 | | |
264 | 254 | | |
265 | | - | |
| 255 | + | |
| 256 | + | |
266 | 257 | | |
267 | 258 | | |
268 | 259 | | |
| |||
285 | 276 | | |
286 | 277 | | |
287 | 278 | | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | 279 | | |
303 | 280 | | |
304 | 281 | | |
| |||
383 | 360 | | |
384 | 361 | | |
385 | 362 | | |
386 | | - | |
| 363 | + | |
387 | 364 | | |
388 | 365 | | |
389 | 366 | | |
| |||
423 | 400 | | |
424 | 401 | | |
425 | 402 | | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | 403 | | |
432 | 404 | | |
433 | 405 | | |
434 | 406 | | |
435 | 407 | | |
436 | 408 | | |
437 | | - | |
438 | | - | |
439 | | - | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
440 | 412 | | |
441 | | - | |
442 | | - | |
443 | | - | |
| 413 | + | |
444 | 414 | | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | 415 | | |
452 | 416 | | |
453 | 417 | | |
| |||
462 | 426 | | |
463 | 427 | | |
464 | 428 | | |
465 | | - | |
466 | 429 | | |
467 | 430 | | |
468 | 431 | | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
469 | 439 | | |
470 | 440 | | |
471 | 441 | | |
| |||
475 | 445 | | |
476 | 446 | | |
477 | 447 | | |
478 | | - | |
479 | | - | |
480 | 448 | | |
481 | 449 | | |
482 | 450 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
| 296 | + | |
| 297 | + | |
301 | 298 | | |
302 | 299 | | |
303 | 300 | | |
304 | | - | |
305 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
306 | 309 | | |
307 | 310 | | |
308 | 311 | | |
| |||
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
0 commit comments