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

when <select> model and the option list changed at the same time, model may incorrectly set to undefined #10614

Open
xieranmaya opened this issue Oct 10, 2019 · 6 comments · May be fixed by #10615

Comments

@xieranmaya
Copy link

xieranmaya commented Oct 10, 2019

Version

2.6.10

Reproduction link

https://jsfiddle.net/4fyrj95L/

Steps to reproduce

set model binded to select element and the array that iterated the option list at the same time

make sure the new model value do not match any of the new options

the model will be set to undefined

What is expected?

model value to be set to 1

What is actually happening?

model's value set to undefined


This bug only appears when model and the options changed at the same and the new model value does not match any option, other situations behaves correctly as far as I tested.

xieranmaya added a commit to xieranmaya/vue that referenced this issue Oct 10, 2019
@posva
Copy link
Member

posva commented Oct 10, 2019

as a workaround you can set a key on the select element that changes alongside the selected list

@xieranmaya
Copy link
Author

xieranmaya commented Oct 11, 2019

It has nothing to do with the key, add key or keys do not resolve the problem.
Acturally the bug is triggered by an internal logic.
See the pr I created above.
@posva

@posva
Copy link
Member

posva commented Oct 11, 2019

A workaround is only a temporary fix for the problem for you or anybody to have a solution until a fix is released: The original problem has nothing to deal with keys yet, adding a key does remove the bug

@despreston
Copy link
Contributor

@posva Maybe im reading the description incorrectly but this sounds like expected behavior. If i change the list of available options, and then change the value to something not in the list of available options, it should be undefined, right?

@posva
Copy link
Member

posva commented Jan 14, 2020

It should keep the set value instead of changing it to undefined

@xieranmaya
Copy link
Author

This issue is owned by the logic of the code:
https://github.com/vuejs/vue/pull/10615/files
the $selectedValue variable in line 121 may be an empty array, but the subsequent code read its first element, if the code is in c/c++, that would be an error or index out of bound.
setting it to undefined is just an accident.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants