Skip to content

docs(nuxt): explain stable keys in dynamic lists - #930

Open
MuslumYilmaz wants to merge 1 commit into
vuetifyjs:masterfrom
MuslumYilmaz:docs/nuxt-stable-list-keys
Open

docs(nuxt): explain stable keys in dynamic lists#930
MuslumYilmaz wants to merge 1 commit into
vuetifyjs:masterfrom
MuslumYilmaz:docs/nuxt-stable-list-keys

Conversation

@MuslumYilmaz

Copy link
Copy Markdown

Documentation gap

The “Avoiding Hydration Mismatch” section already recommends deterministic
v-for keys and warns against index-based keys for dynamic lists. It does not
explain an important distinction: an array index may be identical during the
initial server and client render, yet still represent the wrong logical item
after an insertion, removal, or reorder.

That can cause Vue to reuse component or DOM identity for a different item,
allowing local state, focus, or uncontrolled input values to appear on the
wrong row.

Proposed documentation change

Add a short explanation and a minimal before/after example:

  • Avoid :key="index" when the list can change order or membership.
  • Prefer a stable identifier owned by the item, such as :key="item.id".
  • Clarify that stable keys do not repair mismatched server/client data; the
    initial item sequence and keys must still agree during hydration.

This would expand the existing recommendation without changing any Vuetify0
API or runtime behavior.

Optional reader exercise

For readers who want to reproduce the identity problem with insertion and
reordering, this focused exercise may be useful:
https://frontendatlas.com/vue/trivia/vue-v-for-keys-why-not-index

Disclosure: I maintain FrontendAtlas. The external exercise is optional and can
be omitted if the project prefers to keep the explanation self-contained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant