All rules

Sheath rule

blade-alpine-for-key-integrity

Alpine loop keys must be capable of distinguishing repeated nodes.
Package
Core
Category
Blade
Default severity
warning by default
Auto-fix
Manual fix

#Why

Plain key attributes and bound Alpine loop keys are reported when they are provably constant, arrays, or objects. These values cannot provide stable, distinct identity for repeated x-for items.

Alpine keys are optional, so absence is accepted. Expressions derived from the loop item or index and unknown dynamic expressions are accepted. A constant key is also harmless for a statically empty or single-item collection.

#Examples

#Bad

<template x-for="item in items" :key="'item'">
<div x-text="item.name"></div>
</template>

#Good

<template x-for="item in items" :key="item.id">
<div x-text="item.name"></div>
</template>