Why keyed lists matter when someone is typing
An editable row needs an identity that survives reordering. Try the live example, then see what a key preserves and what happens when filtering removes a row.

A list can look correct while behaving badly. You type a note beside one person, reorder the rows, and the note disappears or ends up beside someone else. The names are in the right order, but the relationship between a person and their input has been lost.
A stable key lets a renderer recognise the same item after the collection changes. In Domma Reactive, a retained keyed row keeps its existing DOM elements. That matters whenever a row holds something beyond its displayed text.
Try it with an input the model does not know about
Type a different note beside each person, then press Reverse or Last to first. Each note travels with its person. Add a row and check that the existing notes remain.
The note inputs have no binding at all. They keep what you typed because each row is the same element, moved - not rebuilt.
The note fields deliberately have no model binding. The demonstration depends on the actual input elements surviving, rather than on a model restoring their values after a rebuild.
<div class="demo-stage">
<div class="demo-controls">
<button class="btn btn-sm" data-on-click="reverse">Reverse</button>
<button class="btn btn-sm" data-on-click="rotate">Last to first</button>
<button class="btn btn-sm btn-primary" data-on-click="add">Add a row</button>
</div>
<ul class="demo-list rx-rows" data-each="rows.value key=id">
<li class="rx-row">
<span class="rx-row-name" data-bind-text="name"></span>
<input class="form-input" aria-label="Note for this person" placeholder="Type a note here, then reorder">
<button class="btn btn-sm btn-ghost" data-on-click="$parent.remove($data)" aria-label="Remove">×</button>
</li>
</ul>
<p class="demo-note">The note inputs have no binding at all. They keep what you typed because each row is the same element, moved - not rebuilt.</p>
</div>A key answers: which item is this?
The important attribute is data-each="rows.value key=id". The list reads its rows and uses each row's id to recognise it during reconciliation.
Here is the model used by the demo:
/**
* Keyed lists keep their DOM.
*
* `data-each="rows.value key=id"` reconciles by key: a row that stays in the list
* keeps its actual element, so the note you typed into it - which no binding
* knows about - travels with it when the list is reordered.
*/
function identity() {
let next = 4;
const rows = observableArray([
{id: 1, name: 'Ada Lovelace'},
{id: 2, name: 'Grace Hopper'},
{id: 3, name: 'Katherine Johnson'}
]);
return {
rows,
reverse() { rows.reverse(); },
rotate() { rows.unshift(rows.pop()); },
add() { rows.push({id: next, name: `New person ${next++}`}); },
remove(row) { rows.remove(row); }
};
}Reverse changes their order. Add introduces a new identity. Remove ends one row's presence in the collection. Those are different operations, and the renderer has enough information to treat them differently.
A good key is unique within the list and stable for the lifetime of an item. An existing database ID is often suitable. An application can also assign an ID when an item is created, as this example does.
A row's position is a poor identity: sorting changes it. A person's editable name is also a poor identity: changing the name should update that person's row, rather than make the renderer treat it as a new person.
Preserve the element that owns the state
An input element holds a current value, selection and other browser-managed state. Rebuilding the row discards that element. Updating its text or moving the existing row lets the element continue to represent the same item.
Keyed reconciliation helps preserve that continuity for rows that remain mounted. It also avoids rebuilding the other rows when you add or remove an item. Moving an element can still interact with browser focus behaviour, so test keyboard interaction in your target browsers as well as checking the visible result.
Filtering has a boundary
A key is not a store for discarded elements. If filtering removes a row from the rendered collection, its DOM is removed. When that item appears again, it receives a new row.
An unbound note like the ones in this demonstration will therefore be lost if its row is removed. If a draft must survive filtering, store it on the item's view model and bind the input to that observable. The model then owns the draft even while no row is displaying it.
The same decision applies to an expanded panel or an editing flag. Put state on the item when it needs to outlive the item's current DOM. Use stable keys to preserve the elements of items that remain visible.
Keep collection changes and field changes distinct
An observableArray tracks changes to the collection, such as adding, removing and reordering items. It does not automatically turn every field on an item into an observable.
The names in this small demo are plain strings because they never change. An editable contact name or a saved draft should be an observable of its own. The contacts tutorial shows that distinction in a complete application, including per-row editing state.
Build from the behaviour you need
Use stable keys wherever a collection renders editable rows, components or other elements with state. Keep state in the model when it must survive a row leaving the rendered list. Check both reordering and filtering when you test the finished interface.
Read the keyed-list guide for the binding details, or start with Your first reactive page before building the larger contacts example.
