Subscribe on changes!

Textarea content still maintain when I leave the router and go to new router

avatar
Jan 17th 2022

Version

3.2.27

Reproduction link

codepen.io

Steps to reproduce

  1. click Index link
  2. click Editor link
  3. click back button
  4. click new Editor link

What is expected?

When I click the editor link, it show "hello world" in textarea, click back button and click newEditor should show nothing in textarea.

What is actually happening?

When I click the editor link, it show "hello world" in textarea, click back button and click newEditor is still show "hello world"


  1. I found it work when I use development version.
  2. In production version, I still found two ways can work. add ref or put the div with id "editor" in root div in components. It seems not destroy the div, even if I make quillEditor is null.
avatar
Jan 17th 2022

I think this has nothing to do with vue.

// if new content is not empty it works fine.
this.content = Number(this.create) ? "<p>Hello World!</p>" : "new val"; 
avatar
Jan 17th 2022

I think this has nothing to do with vue.

// if new content is not empty it works fine.
this.content = Number(this.create) ? "<p>Hello World!</p>" : "new val"; 

But in vue2 it works good. https://codepen.io/cyanxxx/pen/LYzarZP

I think this has nothing to do with vue.

// if new content is not empty it works fine.
this.content = Number(this.create) ? "<p>Hello World!</p>" : "new val"; 

But in vue2, same code can work well. https://codepen.io/cyanxxx/pen/LYzarZP

avatar
Jan 18th 2022

Your reproduction is not minimal, please read and follow https://new-issue.vuejs.org/?repo=vuejs/vue-next#why-repro when reporting a bug. Most bugs should be reproducible with the SFC Playground. Try reproducing without quill or router.

avatar
Jan 24th 2022

Your reproduction is not minimal, please read and follow https://new-issue.vuejs.org/?repo=vuejs/vue-next#why-repro when reporting a bug. Most bugs should be reproducible with the SFC Playground. Try reproducing without quill or router.

https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHNjcmlwdD5cbmltcG9ydCBlZGl0b3JDb250YWluZXIgZnJvbSAnLi9lZGl0b3JDb250YWluZXIudnVlJ1xuaW1wb3J0IGluZGV4IGZyb20gJy4vaW5kZXgudnVlJ1xuZXhwb3J0IGRlZmF1bHR7XG4gICBjb21wb25lbnRzOiB7XG4gICAgZWRpdG9yQ29udGFpbmVyLFxuICAgIGluZGV4XG4gIH0sXG4gIGRhdGEoKSB7XG4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WZvcmVVbm1vdW50KCgpID0+IHtcbiAgICAgICAgY29uc29sZS5sb2coJ29uQmVmb3JlVW5tb3VudCcpXG4gICAgICAgIHF1aWxsRWRpdG9yID0gbnVsbFxuICAgIH0pXG4gICB3YXRjaChjb250ZW50LCAobmV3VmFsLCBvbGRWYWwpID0+IHtcbiAgICAgIGlmIChuZXdWYWwgJiYgIW9sZFZhbCkge1xuICAgICAgICBjb25zb2xlLmxvZygnd2F0Y2gnLCBuZXdWYWwpXG4gICAgICAgIGNvbnN0IGVkaXRvcklucHV0ID0gZG9jdW1lbnQucXVlcnlTZWxlY3RvcihcIiNlZGl0b3IgLnFsLWVkaXRvclwiKTtcbiAgICAgICAgZWRpdG9ySW5wdXQuaW5uZXJIVE1MID0gbmV3VmFsXG4gICAgICAgIGVkaXRvcklucHV0LmZvY3VzKCk7XG4gICAgICB9XG4gICAgfSk7XG4gIH1cbn1cbjwvc2NyaXB0PlxuXG48dGVtcGxhdGU+XG48ZGl2PlxuICAgIDxkaXYgaWQ9XCJlZGl0b3JcIj48L2Rpdj5cbiA8L2Rpdj5cbjwhLS0gPGRpdiBpZD1cImVkaXRvclwiPjwvZGl2PiAtLT5cbiA8IS0tPGRpdj5cbiAgICA8ZGl2IGlkPVwiZWRpdG9yXCIgcmVmPVwiZWRpdG9yXCI+PC9kaXY+XG4gPC9kaXY+IC0tPlxuPC90ZW1wbGF0ZT4ifQ== I hope it clear enough. I am not good at realize router and quill. And the same result is work in development version, but the production version not work.

avatar
May 4th 2022

Finally, I find the problem. Because the hoisted vnode. The '#editor' will be consider as static element. First time will be created and the second time beacuse the vnode was created before, the vnode.el already been set. So it just clone the el element. And because the branch condition, development will not cloneNode so the development environment work. And production not work. https://github.com/vuejs/core/blob/4e7b36f5c3ee72cb9554982dd174f1989d5488f6/packages/runtime-core/src/renderer.ts#L632