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

[template-compiler] Using both v-bind:value and v-model on an input generates code that'S invalid in IE #7048

Closed
LinusBorg opened this issue Nov 12, 2017 · 4 comments

Comments

@LinusBorg
Copy link
Member

Version

2.5.3

Reproduction link

https://vuejs.org/v2/guide/render-function.html#Template-Compilation

(Alternative reproduction on jsfiddle: https://jsfiddle.net/Linusborg/pqbppg7a/)

Steps to reproduce

  1. Paste the following piece of HTML into the textarea of the linked documentation chapter above.
<input type="text" v-bind:value="message" v-model="message">
  1. Inspect the code of the created render function, especially the domProps options:
domProps: {
  "value": message,
  "value": (message)
},

What is expected?

The code should run in all browsers, or throw an error or warning.

What is actually happening?

IE11 throws an error: "duplicate properties not allowed in strict mode".


I realize that using both v-bind:value and v-model on an input is not recommended or even sensible, but it doesn't throw an error or warning when done in modern browsers, and doesn't create any problems if the expression is the same for both, so it can easily be overlooked when added accidentally.

Uglify also doesn't help - it doesn't remove the first occurrence that would otherwise be "overwritten" by the second in modern browsers.

So what would be a sensible solution? I'm not sure.

  • We could adjust the codegen of domProps to check for a double occurence of the value prop on elements of type "input" and drop all but the last occurrence. Possible Problem: performance?
  • We could log a warning to console (how to deal with that in vue-loader?)
  • We could throw an error, forcing the user to choose between the two (breaking change)
  • we could improve awareness by adding a warning to docs and a rule to eslint-plugin-vue?
@yyx990803
Copy link
Member

I think this can be dealt with by a compile-time warning at the parsing phase (when v-model and v-bind:value are detected on the same element)

yyx990803 pushed a commit that referenced this issue Nov 16, 2017
* test($compile): warn if v-model and :value used on same text input

#7048

* test($compile): make v-model and v-bind:value warning apply to all but exceptions

#7048

* test($compile): move v-model/:value conflict warner to model.js

#7048

* style: split long warning messages onto new lines
@justsrik
Copy link

justsrik commented Nov 17, 2017

I am getting compiling errors not warnings when I do 'npm run dev' on my code base. @yyx990803 @ @rpemberton @LinusBorg. Just to update I am running vue@2.5.5 and vue-template-compiler@2.5.5.

@yyx990803
Copy link
Member

You should fix them because they are not supposed to work in the first place.

@justsrik
Copy link

Thanks for your reply @yyx990803, removed :value. Thanks

lovelope pushed a commit to lovelope/vue that referenced this issue Feb 1, 2018
…js#7056)

* test($compile): warn if v-model and :value used on same text input

vuejs#7048

* test($compile): make v-model and v-bind:value warning apply to all but exceptions

vuejs#7048

* test($compile): move v-model/:value conflict warner to model.js

vuejs#7048

* style: split long warning messages onto new lines
f2009 pushed a commit to f2009/vue that referenced this issue Jan 25, 2019
…js#7056)

* test($compile): warn if v-model and :value used on same text input

vuejs#7048

* test($compile): make v-model and v-bind:value warning apply to all but exceptions

vuejs#7048

* test($compile): move v-model/:value conflict warner to model.js

vuejs#7048

* style: split long warning messages onto new lines
aJean pushed a commit to aJean/vue that referenced this issue Aug 19, 2020
…js#7056)

* test($compile): warn if v-model and :value used on same text input

vuejs#7048

* test($compile): make v-model and v-bind:value warning apply to all but exceptions

vuejs#7048

* test($compile): move v-model/:value conflict warner to model.js

vuejs#7048

* style: split long warning messages onto new lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants