-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Dev build console error when using index in :key value with v-for and transitions #8730
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
Comments
This is not possible because sometimes you may want to use the index as the key. |
You would never want to use index as the key with a transition because it causes an error. I demonstrated that. Is there something wrong with my example showing this error? |
Yeah, you are right. I don't think it makes sense to use the index in any scenario for transition-group. I'm not sure this is an easy to add warning though |
If I get to a point where I have more free time, I'd at least look through the code to be able to add this kind of thing. Perhaps a dev only object that tracks features being used during a render (ie, transition is used) then when an index is found (ie, in the template render?) it would be tracked as well, and then conflicts could be found between features used. I know it's easy to say this kind of thing, and a whole other thing to actually build it. But I am not a high level dev, so I can only theorize... |
In dev branch this issue is solved, why is still open? |
It wasn't correctly reference I the commit message of the PR #8748 |
What problem does this feature solve?
Currently there is no obvious way to debug an error when including the index value in v-bind:key with v-for when using transitions. This causes erratic and unexpected behavior from transitions (and I would suspect other side effects, but these are untested).
This feature would alert the developer that they have used index value in a place where it will cause errors with transitions.
Example error:
This example should illustrate how difficult it is to determine why the v-for combined with transition-group fails.
In the example below there are 3 uses of v-for with :key. (1) one works fine, it doesn't include index in the :key value. (2) uses index as the key (ie, v-bind:key="index"). (3) uses a concatenated version (v-bind:key="item '_' index"
https://codepen.io/megacromulent/pen/gdMYLx?editors=1010
Note: this behavior was thought to be a bug because of lack of documentation on this behavior ( #8718 ) and having a console log entry would have solved the confusion instantly during development, instead of hours of debugging and reporting.
What does the proposed API look like?
Check to see if the index value is used anywhere in :key, and then check if a transition is being used, if so, then display console error, or at least a warning.
The proposal is for the dev builds only, so no additions/expansions to the API are needed for the production builds.
The text was updated successfully, but these errors were encountered: