Skip to content

Compiler not allowing correct usage of <transition-group> keys #5360

@petterw03

Description

@petterw03

Version

3.2.29

Reproduction link

sfc.vuejs.org/

Steps to reproduce

Open the reproduction code.

What is expected?

Code should compile and transitions should work fluently when clicking the buttons.

What is actually happening?

It will not compile because of the key property on the group headings:

SyntaxError: <template v-for> key should be placed on the <template> tag.

App.vue
19 |    <transition-group name="cell" tag="div" class="grid">
20 |      <template v-for="group in groups" :key="group.id">
21 |        <h2 :key="`title-${group.id}`">{{ group.name }}</h2>
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
22 |        <div v-for="letter in group.letters" :key="letter">{{ letter }}</div>
23 |      </template>

Removing the key will throw a warning:

 at <TransitionGroupname="cell"tag="div"class="grid">

This warning is correct, because without a key the transitions will not work as expected when adding or removing items from the groups array.


There are a couple of similar issues (#4718, #5152), but they are not duplicates of this one since they are focusing on the warning when a key is not used. But in this case, a key is needed but the code won't compile, even though it is valid code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions