diff --git a/.changeset/honest-icons-change.md b/.changeset/honest-icons-change.md new file mode 100644 index 0000000000..6791a930d5 --- /dev/null +++ b/.changeset/honest-icons-change.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +patch: ensure keyed each block fallback to indexed each block diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js index 66ec08d782..02483544ad 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js @@ -2066,7 +2066,10 @@ export const template_visitors = { /** @type {number} */ let each_type; - if (node.key) { + if ( + node.key && + (node.key.type !== 'Identifier' || !node.index || node.key.name !== node.index) + ) { each_type = EACH_KEYED; if ( node.key.type === 'Identifier' && diff --git a/packages/svelte/tests/runtime-legacy/samples/keyed-each-index-same/_config.js b/packages/svelte/tests/runtime-legacy/samples/keyed-each-index-same/_config.js new file mode 100644 index 0000000000..a1d9fe1b26 --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/keyed-each-index-same/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + html: '1' +}); diff --git a/packages/svelte/tests/runtime-legacy/samples/keyed-each-index-same/main.svelte b/packages/svelte/tests/runtime-legacy/samples/keyed-each-index-same/main.svelte new file mode 100644 index 0000000000..7a6f0e08fa --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/keyed-each-index-same/main.svelte @@ -0,0 +1,3 @@ +{#each [1] as item, i (i)} + {item} +{/each}