A list needs a key
The message
MARKLESS_REPEAT_KEY_REQUIRED: @for (const <itemName> of <collectionSource>) repeats reactive state without a key. When <collectionSource> changes, the rows of this list have no identity to update, reorder, or resume by.
A keyed loop item keeps its state, events, and DOM attached to the same logical item across reorder, insert, and delete; without a key there is no stable identity root.
Add a stable domain key such as `@for (const <itemName> of <collectionSource>; key <itemName>.id)`, or key by position with `index i; key i` when state should follow the slot.
https://markless.dev/errors/MARKLESS_REPEAT_KEY_REQUIREDWords in angle brackets change from case to case.
Why
Every @for inside an element needs a key, even one over a fixed list. Without a key, Markless cannot tell which row is which when the list changes.
Fix
Add a key that stays the same for each item, like an id. If state belongs to the position in the list, key by the index instead.
Before
import { state } from '@markless/core';export function Guests() @{ let guests = state([{ id: 1, name: 'Ada' }]); <ul> @for (const guest of guests) { <li>{guest.name}</li> } </ul>}After
@for (const guest of guests; key guest.id) { <li>{guest.name}</li>}