Skip to content

Commit

Permalink
fix: adjust keyed each block equality handling
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Mar 5, 2024
1 parent 86f3265 commit a0f8c6f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-masks-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: adjust keyed each block equality handling
8 changes: 6 additions & 2 deletions packages/svelte/src/internal/client/dom/blocks/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { current_block, destroy_signal, execute_effect, push_destroy_fn } from '
import { render_effect } from '../../reactivity/effects.js';
import { source, mutable_source, set } from '../../reactivity/sources.js';
import { trigger_transitions } from '../../transitions.js';
import { is_array } from '../../utils.js';
import { EACH_BLOCK, EACH_ITEM_BLOCK } from '../../constants.js';
import { is_array, is_frozen } from '../../utils.js';
import { EACH_BLOCK, EACH_ITEM_BLOCK, STATE_SYMBOL } from '../../constants.js';

const NEW_BLOCK = -1;
const MOVED_BLOCK = 99999999;
Expand Down Expand Up @@ -449,6 +449,10 @@ function reconcile_tracked_array(
apply_transitions,
keys
) {
// If we are working with an array that isn't proxied or frozen, then remove strict equality.
if ((flags & EACH_IS_STRICT_EQUALS) !== 0 && !is_frozen(array) && !(STATE_SYMBOL in array)) {
flags ^= EACH_IS_STRICT_EQUALS;
}
var a_blocks = each_block.v;
const is_computed_key = keys !== null;
var active_transitions = each_block.s;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
html: `100\n<button>Update</button>`,

async test({ assert, target }) {
/**
* @type {{ click: () => void; }}
*/
let btn1;

[btn1] = target.querySelectorAll('button');

flushSync(() => {
btn1.click();
});

assert.htmlEqual(target.innerHTML, `1000\n<button>Update</button>`);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
import { writable } from "svelte/store";
const roomState = writable({
users: {"gary": { name: "gary", value: 100 }},
});
</script>

{#each Object.values($roomState.users) as user (user.name)}
{user.value}
{/each}

<button onclick={() => $roomState.users["gary"].value = 1000}>Update</button>

0 comments on commit a0f8c6f

Please sign in to comment.