Vue: Firefox - changing anything on element via $refs table breaks the binding

Created on 12 Mar 2018  路  2Comments  路  Source: vuejs/vue

Version

2.5.15

Reproduction link

Steps to reproduce

  1. Create vue.js instance and add data field to it.
  2. Create new "title" property.
  3. In your app create any element and output in it your "title".
  4. Add ref to your element.
  5. Change "title" in your app using some method.
  6. Change "title" via $refs table.
  7. Change back "title" via your method.

What is expected?

Your "title" should change back to what was set by your method.

What is actually happening?

Title can't be changed anymore by your method. Vue is losing the binding to the element after it's updated via $refs.


This happens only on Firefox (I'm using 60.0b2), other browsers (chrome, chromium) are fine.

Most helpful comment

This is because when you set innerText, it throws aways the current TextNodes inside the element and creates new ones. However, Vue is still holding on to the TextNodes for subsequent updates.

Note it's not recommended to mutate nodes via refs unless you absolutely need to. That said, to change the text without replacing the text nodes, use

vm1.$refs.heading.childNodes[0].data = 'Something else';

All 2 comments

This is because when you set innerText, it throws aways the current TextNodes inside the element and creates new ones. However, Vue is still holding on to the TextNodes for subsequent updates.

Note it's not recommended to mutate nodes via refs unless you absolutely need to. That said, to change the text without replacing the text nodes, use

vm1.$refs.heading.childNodes[0].data = 'Something else';

But why then it happens only in Firefox and not in Chrome?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bdedardel picture bdedardel  路  3Comments

julianxhokaxhiu picture julianxhokaxhiu  路  3Comments

paceband picture paceband  路  3Comments

gkiely picture gkiely  路  3Comments

6pm picture 6pm  路  3Comments