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

Contenteditable receiving duplicate values #5805

Closed
timwis opened this issue Jun 2, 2017 · 7 comments
Closed

Contenteditable receiving duplicate values #5805

timwis opened this issue Jun 2, 2017 · 7 comments

Comments

@timwis
Copy link

timwis commented Jun 2, 2017

Version

2.3.3

Reproduction link

https://codepen.io/timwis/pen/YQKXBY

Steps to reproduce

Type something in the box below, click outside the area (to blur), and watch it appear double.

What is expected?

The editable div keeps what you typed in it.

What is actually happening?

The editable div adds what you typed in it assumedly as part of the virtual dom update, showing it twice.


My hunch is this is an issue with how virtual dom patches a <div contenteditable> that starts with an empty value. If you change its starting value in the demo to an actual value (like foo) this issue doesn't happen.

Related to #5234. Let me know if you prefer we keep the conversation there and we can close this issue.

@defcc
Copy link
Member

defcc commented Jun 2, 2017

Why not use v-html directive? I updated the link here https://codepen.io/anon/pen/MoWgJZ

@posva
Copy link
Member

posva commented Jun 2, 2017

As you commented in the other issue, the behaviour is incosistent but contenteditable is quite weird itself. Using v-text or v-html fixes the issue but {{}} should be the same as v-html

@yyx990803
Copy link
Member

This type of usage will be a wontfix. v-text or v-html works by wiping away the pre-existing content with completely new nodes; however when you use {{ }} bindings Vue will attempt to diff the text nodes - which will likely be made out of sync by contenteditable because how browsers handle/split the text nodes are completely unpredictable.

@timwis
Copy link
Author

timwis commented Jun 3, 2017

Confirmed that v-text does the trick. Thanks!

@martinesdevelop
Copy link

v-text helped me

@Aymkdn
Copy link

Aymkdn commented Nov 6, 2019

For people using render with createElement(), you need to use domProps:

return createElement('div', {
  attrs:{
    cotenteditable:true
  },
  domProps:{
    innerText:this.content
  }
}, '');

@Alinawaz-786
Copy link

Alinawaz-786 commented Nov 6, 2019 via email

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

7 participants