Skip to content

Commit

Permalink
fix: ensure keyed fallback to indexed (#9441)
Browse files Browse the repository at this point in the history
Fixes #9408. Ensures that if we have a key that matches the index, that we fallback to using an indexed each block.
  • Loading branch information
trueadm committed Nov 14, 2023
1 parent da37c92 commit cf63220
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/honest-icons-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

patch: ensure keyed each block fallback to indexed each block
Original file line number Diff line number Diff line change
Expand Up @@ -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' &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test } from '../../test';

export default test({
html: '1'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{#each [1] as item, i (i)}
{item}
{/each}

1 comment on commit cf63220

@vercel
Copy link

@vercel vercel bot commented on cf63220 Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svelte-5-preview – ./sites/svelte-5-preview

svelte-5-preview-git-main-svelte.vercel.app
svelte-5-preview-svelte.vercel.app
svelte-5-preview.vercel.app
svelte-octane.vercel.app

Please sign in to comment.