Subscribe on changes!

No warning in console on rendered list without specifying key attribute

avatar
Jun 5th 2023

Vue version

3.3.2

Link to minimal reproduction

https://play.vuejs.org/#eNp9js0OwiAQhF9lwqWXWjw31MTnEA+10oQEgZSfgw3v7grGk/G0P7M73+zs7P2Qk2IjE2HZtI8IKiZ/knZxNkToqB4BEy7SAjv0fcSxR55NUiO61bkOpf+p3ebtj/YkTdqrtII3LhFpIJo3c1Q0ASKZWqkzGvmwum2S7J0I2rZkkn0uCEIUWg2VgULu9ZMb3cx4dRP8i2DlBdZ1UXI=

Steps to reproduce

Example ready as is.

What is expected?

I expect to have warning in console on list being rendered using v-for without binding the key attribute. Like it was in Vue 2 (component lists rendered with v-for should have explicit keys. See https://v2.vuejs.org/v2/guide/list.html#key for more info.) or like it is now in React.

What is actually happening?

No warning is being shown.

System Info

No response

Any additional comments?

No response

avatar
Jun 5th 2023

You don't actually need key on v-for loops in Vue 3:

https://v3-migration.vuejs.org/breaking-changes/key-attribute.html

avatar
Jun 7th 2023

@LinusBorg That documentation doesn't mention anywhere that key isn't needed on v-for - it only says so about v-if. Can the docs be updated as a source of truth? (e.g. google finds this SO post https://stackoverflow.com/a/70987261)

avatar
Jun 7th 2023

@LinusBorg That documentation doesn't mention anywhere that key isn't needed on v-for - it only says so about v-if. Can the docs be updated as a source of truth? (e.g. google finds this SO post https://stackoverflow.com/a/70987261)

Was about to say the same thing.

avatar
Jun 8th 2023

Yeah i got something mixed up with that migrationg guide link.

Yet in a sense it still applies: v-for does not always need a key. our docs have a separate section detailing when to use a key:

https://vuejs.org/guide/essentials/list.html#maintaining-state-with-key

Hence why we provide an eslint rule to recommend adding a key, but don't log out a runtime warning from Vue itself.