Skip to content
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

v-for class with Symbol.iterator not working properly when return value is modified #9414

Closed
plehnen opened this issue Feb 4, 2019 · 1 comment

Comments

@plehnen
Copy link

plehnen commented Feb 4, 2019

Version

2.6.0-beta.3

Reproduction link

https://jsfiddle.net/vx1ygurm/

Steps to reproduce

Iterate with v-for on a class with Symbol.iterator (which does something with the returning value). See jsfiddle!

What is expected?

since 2.6-beta1 it should support iterables in v-for (#8179) d40eb9c, (#8179)

I thought, great, let's try this with my footnote class and get rid of that verbose "getItems()" accessor and directly pass the class with a Symbol.iterator.

What is actually happening?

But as soon as the values which should be iterated are mutated before they are returned (e.g. sort), it shows the Vue warn:
"You may have an infinite update loop in a component render function."

And the iterator gets called over 100 times.


Even worse, if you put this class in a vuex state. Then it complains that it cannot be mutated (even though I don't actually mutate it)

@plehnen plehnen changed the title v-for class with Symbol.iterator not working properly when returning objects v-for class with Symbol.iterator not working properly when return value is modified Feb 4, 2019
@yyx990803
Copy link
Member

yyx990803 commented Feb 4, 2019

.sort is a mutating method, when you call it it mutates the original array instead of creating a copy.

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

No branches or pull requests

2 participants