Prefer Stable Keys In Lazy Column
`LazyColumn`, `LazyRow`, and `LazyVerticalGrid` use the `key` parameter on each item to identify it across recompositions.…
$ prime install @android-compose/rule-prefer-stable-keys-in-lazy-column Projection
Always in _index.xml · the agent never has to ask for this.
PreferStableKeysInLazyColumn [rule] v0.1.0
LazyColumn, LazyRow, and LazyVerticalGrid use the key parameter on each item to identify it across recompositions. Without a key, Compose falls back to position — which means inserting at the head re-keys every following item, animations break, scroll position drifts, and per-item state (like a remembered expand flag) jumps to the wrong row. Pass a key = { item -> item.id } whose value is stable for the lifetime of that item.
Loaded when retrieval picks the atom as adjacent / supporting.
PreferStableKeysInLazyColumn [rule] v0.1.0
LazyColumn, LazyRow, and LazyVerticalGrid use the key parameter on each item to identify it across recompositions. Without a key, Compose falls back to position — which means inserting at the head re-keys every following item, animations break, scroll position drifts, and per-item state (like a remembered expand flag) jumps to the wrong row. Pass a key = { item -> item.id } whose value is stable for the lifetime of that item.
Checks
- Every
items(...)anditemsIndexed(...)call has an explicitkey = { ... }lambda when the list is mutable or paginated. - Keys are unique within the list and stable across reorderings (typically a primary-key id from the data model).
- Keys are NOT the index, NOT the hashCode of the whole item, NOT a randomly generated value at composition time.
- Keys are types Compose treats as Saveable (Int, Long, String, parcelable) so list state survives configuration change.
Label
Pass stable, unique key to LazyColumn / LazyRow items
Loaded when retrieval picks the atom as a focal / direct hit.
PreferStableKeysInLazyColumn [rule] v0.1.0
LazyColumn, LazyRow, and LazyVerticalGrid use the key parameter on each item to identify it across recompositions. Without a key, Compose falls back to position — which means inserting at the head re-keys every following item, animations break, scroll position drifts, and per-item state (like a remembered expand flag) jumps to the wrong row. Pass a key = { item -> item.id } whose value is stable for the lifetime of that item.
Checks
- Every
items(...)anditemsIndexed(...)call has an explicitkey = { ... }lambda when the list is mutable or paginated. - Keys are unique within the list and stable across reorderings (typically a primary-key id from the data model).
- Keys are NOT the index, NOT the hashCode of the whole item, NOT a randomly generated value at composition time.
- Keys are types Compose treats as Saveable (Int, Long, String, parcelable) so list state survives configuration change.
Label
Pass stable, unique key to LazyColumn / LazyRow items
Label
Pass stable, unique key to LazyColumn / LazyRow items
Source
prime-system/examples/android-compose/primes/compiled/@android-compose/rule-prefer-stable-keys-in-lazy-column/atom.yaml