fix other case

fix-indexed
Dominic Gannaway 7 months ago
parent caab6cc16c
commit 18bd6b55df

@ -2393,7 +2393,7 @@ export const template_visitors = {
const binding = /** @type {import('#compiler').Binding} */ (context.state.scope.get(item.name)); const binding = /** @type {import('#compiler').Binding} */ (context.state.scope.get(item.name));
binding.expression = (id) => { binding.expression = (id) => {
const item_with_loc = with_loc(item, id); const item_with_loc = with_loc(item, id);
return each_item_is_reactive ? b.call('$.unwrap', item_with_loc) : item_with_loc; return b.call('$.unwrap', item_with_loc);
}; };
if (node.index) { if (node.index) {
const index_binding = /** @type {import('#compiler').Binding} */ ( const index_binding = /** @type {import('#compiler').Binding} */ (
@ -2401,7 +2401,7 @@ export const template_visitors = {
); );
index_binding.expression = (id) => { index_binding.expression = (id) => {
const index_with_loc = with_loc(index, id); const index_with_loc = with_loc(index, id);
return each_item_is_reactive ? b.call('$.unwrap', index_with_loc) : index_with_loc; return b.call('$.unwrap', index_with_loc);
}; };
} }

@ -458,6 +458,10 @@ function reconcile_tracked_array(
// are treated as reactive, so they get wrapped in a signal. // 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)) { if ((flags & EACH_IS_STRICT_EQUALS) !== 0 && !is_frozen(array) && !(STATE_SYMBOL in array)) {
flags ^= EACH_IS_STRICT_EQUALS; flags ^= EACH_IS_STRICT_EQUALS;
// Additionally as we're in an keyed each block, we'll need ensure the itens are all wrapped in signals.
if ((flags & EACH_ITEM_REACTIVE) === 0) {
flags ^= EACH_ITEM_REACTIVE;
}
} }
var a_blocks = each_block.v; var a_blocks = each_block.v;
const is_computed_key = keys !== null; const is_computed_key = keys !== null;

@ -2,7 +2,7 @@ import { flushSync } from 'svelte';
import { test } from '../../test'; import { test } from '../../test';
export default test({ export default test({
html: `1\n1\n<button>+</button>`, html: `1\n1\n1\n1\n<button>+</button>`,
async test({ assert, target }) { async test({ assert, target }) {
/** /**
@ -16,6 +16,6 @@ export default test({
btn1.click(); btn1.click();
}); });
assert.htmlEqual(target.innerHTML, `2\n2\n<button>+</button>`); assert.htmlEqual(target.innerHTML, `2\n2\n2\n2\n<button>+</button>`);
} }
}); });

@ -10,6 +10,12 @@
} }
</script> </script>
{#each $store as item (item)}
{item.value}
{/each}
{#each $storeDeeper.items as item (item)}
{item.value}
{/each}
{#each $store as item} {#each $store as item}
{item.value} {item.value}
{/each} {/each}

Loading…
Cancel
Save