Skip to content

useSvelteRequireEachKey (HTML)

Language HTML
biome.json
{
"linter": {
"rules": {
"nursery": {
"useSvelteRequireEachKey": "error"
}
}
}
}

Require keyed {#each} blocks in Svelte templates.

Svelte uses keyed each blocks to track list items across updates. Without a key, Svelte updates items by position, which can cause state to move between items when the list changes.

For more information, see the Svelte documentation on keyed each blocks.

{#each items as item}
<div>{item}</div>
{/each}
code-block.svelte:1:1 lint/nursery/useSvelteRequireEachKey ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This {#each} block is missing a key.

> 1 │ {#each items as item}
^^^^^^^^^^^^^^^^^^^^^
2 │ <div>{item}</div>
3 │ {/each}

Providing a key helps Svelte track each item when the list changes.

Add a unique key using the (key) syntax, for example: {#each items as item (item.id)}.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

{#each items as item (item.id)}
<div>{item}</div>
{/each}