Skip to content

Commit eedb593

Browse files
authored
fix: adjust keyed each block equality handling (#10699)
Fixes #10685
1 parent 86f3265 commit eedb593

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

.changeset/seven-masks-end.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: adjust keyed each block equality handling

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import { current_block, destroy_signal, execute_effect, push_destroy_fn } from '
2020
import { render_effect } from '../../reactivity/effects.js';
2121
import { source, mutable_source, set } from '../../reactivity/sources.js';
2222
import { trigger_transitions } from '../../transitions.js';
23-
import { is_array } from '../../utils.js';
24-
import { EACH_BLOCK, EACH_ITEM_BLOCK } from '../../constants.js';
23+
import { is_array, is_frozen } from '../../utils.js';
24+
import { EACH_BLOCK, EACH_ITEM_BLOCK, STATE_SYMBOL } from '../../constants.js';
2525

2626
const NEW_BLOCK = -1;
2727
const MOVED_BLOCK = 99999999;
@@ -449,6 +449,10 @@ function reconcile_tracked_array(
449449
apply_transitions,
450450
keys
451451
) {
452+
// If we are working with an array that isn't proxied or frozen, then remove strict equality.
453+
if ((flags & EACH_IS_STRICT_EQUALS) !== 0 && !is_frozen(array) && !(STATE_SYMBOL in array)) {
454+
flags ^= EACH_IS_STRICT_EQUALS;
455+
}
452456
var a_blocks = each_block.v;
453457
const is_computed_key = keys !== null;
454458
var active_transitions = each_block.s;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
html: `100\n<button>Update</button>`,
6+
7+
async test({ assert, target }) {
8+
/**
9+
* @type {{ click: () => void; }}
10+
*/
11+
let btn1;
12+
13+
[btn1] = target.querySelectorAll('button');
14+
15+
flushSync(() => {
16+
btn1.click();
17+
});
18+
19+
assert.htmlEqual(target.innerHTML, `1000\n<button>Update</button>`);
20+
}
21+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
import { writable } from "svelte/store";
3+
4+
const roomState = writable({
5+
users: {"gary": { name: "gary", value: 100 }},
6+
});
7+
</script>
8+
9+
{#each Object.values($roomState.users) as user (user.name)}
10+
{user.value}
11+
{/each}
12+
13+
<button onclick={() => $roomState.users["gary"].value = 1000}>Update</button>

0 commit comments

Comments
 (0)