fix: improve indexed each equality (#10702)

pull/10706/head
Dominic Gannaway 4 months ago committed by GitHub
parent 4285e6d814
commit d9d1022895
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: improve indexed each equality

@ -332,6 +332,11 @@ function reconcile_indexed_array(
flags,
apply_transitions
) {
// If we are working with an array that isn't proxied or frozen, then remove strict equality and ensure the items
// are treated as reactive, so they get wrapped in a signal.
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;
var active_transitions = each_block.s;
@ -449,7 +454,8 @@ 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 we are working with an array that isn't proxied or frozen, then remove strict equality and ensure the items
// are treated as reactive, so they get wrapped in a signal.
if ((flags & EACH_IS_STRICT_EQUALS) !== 0 && !is_frozen(array) && !(STATE_SYMBOL in array)) {
flags ^= EACH_IS_STRICT_EQUALS;
}

@ -0,0 +1,21 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
html: `1\n1\n<button>+</button>`,
async test({ assert, target }) {
/**
* @type {{ click: () => void; }}
*/
let btn1;
[btn1] = target.querySelectorAll('button');
flushSync(() => {
btn1.click();
});
assert.htmlEqual(target.innerHTML, `2\n2\n<button>+</button>`);
}
});

@ -0,0 +1,20 @@
<script>
import { writable } from "svelte/store";
let store = writable([{ value: 1 }]);
let storeDeeper = writable({ items: [{ value: 1 }] });
function increment() {
$store[0].value++;
$storeDeeper.items[0].value++;
}
</script>
{#each $store as item}
{item.value}
{/each}
{#each $storeDeeper.items as item}
{item.value}
{/each}
<button onclick={increment}>+</button>
Loading…
Cancel
Save