Skip to content

Commit 59f7bd6

Browse files
authored
fix: improve await block behaviour in non-runes mode (#12179)
Fixes #12166. Turns out that the recent refactors here negated the fact that non-runes mode uses a slightly different source signal that has different equality rules. I also updated the docs in this PR too to reflect that only plain objects and arrays are proxied.
1 parent e3d8ee6 commit 59f7bd6

File tree

6 files changed

+71
-4
lines changed

6 files changed

+71
-4
lines changed

.changeset/tender-lemons-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: improve await block behaviour in non-runes mode

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { is_promise, noop } from '../../../shared/utils.js';
22
import {
33
current_component_context,
44
flush_sync,
5+
is_runes,
56
set_current_component_context,
67
set_current_effect,
78
set_current_reaction,
@@ -11,7 +12,7 @@ import { block, branch, pause_effect, resume_effect } from '../../reactivity/eff
1112
import { DEV } from 'esm-env';
1213
import { queue_micro_task } from '../task.js';
1314
import { hydrating } from '../hydration.js';
14-
import { set, source } from '../../reactivity/sources.js';
15+
import { mutable_source, set, source } from '../../reactivity/sources.js';
1516

1617
const PENDING = 0;
1718
const THEN = 1;
@@ -27,6 +28,7 @@ const CATCH = 2;
2728
* @returns {void}
2829
*/
2930
export function await_block(anchor, get_input, pending_fn, then_fn, catch_fn) {
31+
var runes = is_runes();
3032
var component_context = current_component_context;
3133

3234
/** @type {any} */
@@ -44,8 +46,10 @@ export function await_block(anchor, get_input, pending_fn, then_fn, catch_fn) {
4446
/** @type {import('#client').Effect | null} */
4547
var catch_effect;
4648

47-
var input_source = source(/** @type {V} */ (undefined));
48-
var error_source = source(undefined);
49+
var input_source = runes
50+
? source(/** @type {V} */ (undefined))
51+
: mutable_source(/** @type {V} */ (undefined));
52+
var error_source = runes ? source(undefined) : mutable_source(undefined);
4953
var resolved = false;
5054

5155
/**
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
export let card;
3+
export let onfav;
4+
</script>
5+
6+
<button on:click={onfav}>
7+
{card.x}
8+
</button>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
async test({ assert, target }) {
5+
await Promise.resolve();
6+
assert.htmlEqual(
7+
target.innerHTML,
8+
`<button>1</button><button>2</button><button>3</button><button>4</button>\n-------`
9+
);
10+
11+
const [b1] = target.querySelectorAll('button');
12+
13+
b1.click();
14+
await Promise.resolve();
15+
assert.htmlEqual(
16+
target.innerHTML,
17+
`<button>2</button><button>3</button><button>4</button>\n-------\n<button>1</button>`
18+
);
19+
}
20+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script>
2+
import Card from './Card.svelte'
3+
4+
const x = [{
5+
fav: false,
6+
x: 1
7+
}, {
8+
fav: false,
9+
x: 2
10+
}, {
11+
fav: false,
12+
x: 3
13+
}, {
14+
fav: false,
15+
x: 4
16+
}];
17+
18+
let p_cards = Promise.resolve(JSON.parse(JSON.stringify(x)));
19+
</script>
20+
21+
{#await p_cards then cards}
22+
{#each cards.filter((card) => !card.fav) as card}
23+
<Card {card} onfav={() => {card.fav = !card.fav}}></Card>
24+
{/each}
25+
-------
26+
{#each cards.filter((card) => card.fav) as card}
27+
<Card {card} onfav={() => {card.fav = !card.fav}}></Card>
28+
{/each}
29+
{/await}
30+

sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Todo {
4040

4141
> In this example, the compiler transforms `done` and `text` into `get`/`set` methods on the class prototype referencing private fields
4242
43-
Objects and arrays [are made deeply reactive](/#H4sIAAAAAAAAE42QwWrDMBBEf2URhUhUNEl7c21DviPOwZY3jVpZEtIqUBz9e-UUt9BTj7M784bdmZ21wciq48xsPyGr2MF7Jhl9-kXEKxrCoqNLQS2TOqqgPbWd7cgggU3TgCFCAw-RekJ-3Et4lvByEq-drbe_dlsPichZcFYZrT6amQto2pXw5FO88FUYtG90gUfYi3zvWrYL75vxL57zfA07_zfr23k1vjtt-aZ0bQTcbrDL5ZifZcAxKeS8lzDc8X0xDhJ2ItdbX1jlOZMb9VnjyCoKCfMpfwG975NFVwEAAA==) by wrapping them with [`Proxies`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy):
43+
Only plain objects and arrays [are made deeply reactive](/#H4sIAAAAAAAAE42QwWrDMBBEf2URhUhUNEl7c21DviPOwZY3jVpZEtIqUBz9e-UUt9BTj7M784bdmZ21wciq48xsPyGr2MF7Jhl9-kXEKxrCoqNLQS2TOqqgPbWd7cgggU3TgCFCAw-RekJ-3Et4lvByEq-drbe_dlsPichZcFYZrT6amQto2pXw5FO88FUYtG90gUfYi3zvWrYL75vxL57zfA07_zfr23k1vjtt-aZ0bQTcbrDL5ZifZcAxKeS8lzDc8X0xDhJ2ItdbX1jlOZMb9VnjyCoKCfMpfwG975NFVwEAAA==) by wrapping them with [`Proxies`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy):
4444

4545
```svelte
4646
<script>

0 commit comments

Comments
 (0)