-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler not allowing correct usage of <transition-group> keys #5360
Comments
possible workaround sfc <transition-group name="cell" tag="div" class="grid">
<template v-for="group in groups" :key="group.id">
<template v-if=true >
<h2 :key="`title-${group.id}`">{{ group.name }}</h2>
<div v-for="letter in group.letters" :key="letter" class="item">{{ letter }}</div>
</template>
</template>
</transition-group> |
Duplicate of #4718 |
Thank you @lidlanca for the workaround, it works well but is indeed a workaround. As already mentioned, this is not a duplicate since the previous issue addresses the console warning - however the console warning isn't a bug but the compiler error is, and it cannot be suppressed or ignored (unlike the warning). |
issues are related and revolve around the same base bug #4718 expects that there will be no warning, since the fragment is keyed, and it doesn't try to key the fragment nodes. However this issue exposes an additional bug There is technically no reason for this should be valid code <template v-for="item in items" :key="item.i">
<h1>chart</h1>
<chart :key="refresh[item.id]"></chart>
</template> independent of |
I've been able to remedy this issue by removing the block of code that validates this specific condition. Line 155 of errors.ts: Line 121 of vFor.ts:
Before I make a PR, I just wanted to confirm that this is actually an issue and that simply removing this code is a satisfactory solution. It looks like this was intentionally added by @yyx990803 back in 2020:
|
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:Removing the key will throw a warning:
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.
The text was updated successfully, but these errors were encountered: