@@ -533,6 +533,20 @@ class RichTextEditor extends ElementMixin(ThemableMixin(PolymerElement)) {
533533 }
534534 }
535535
536+ /** @protected */
537+ disconnectedCallback ( ) {
538+ super . disconnectedCallback ( ) ;
539+
540+ // Ensure that htmlValue property set before attach
541+ // gets applied in case of detach and re-attach.
542+ if ( this . __debounceSetValue && this . __debounceSetValue . isActive ( ) ) {
543+ this . __debounceSetValue . flush ( ) ;
544+ }
545+
546+ this . _editor . emitter . removeAllListeners ( ) ;
547+ this . _editor . emitter . listeners = { } ;
548+ }
549+
536550 /** @private */
537551 __setDirection ( dir ) {
538552 // Needed for proper `ql-align` class to be set and activate the toolbar align button
@@ -554,18 +568,14 @@ class RichTextEditor extends ElementMixin(ThemableMixin(PolymerElement)) {
554568 }
555569
556570 /** @protected */
557- ready ( ) {
558- super . ready ( ) ;
571+ connectedCallback ( ) {
572+ super . connectedCallback ( ) ;
559573
560574 const editor = this . shadowRoot . querySelector ( '[part="content"]' ) ;
561- const toolbarConfig = this . _prepareToolbar ( ) ;
562- this . _toolbar = toolbarConfig . container ;
563-
564- this . _addToolbarListeners ( ) ;
565575
566576 this . _editor = new Quill ( editor , {
567577 modules : {
568- toolbar : toolbarConfig ,
578+ toolbar : this . _toolbarConfig ,
569579 } ,
570580 } ) ;
571581
@@ -577,10 +587,6 @@ class RichTextEditor extends ElementMixin(ThemableMixin(PolymerElement)) {
577587 this . __patchFirefoxFocus ( ) ;
578588 }
579589
580- this . $ . linkDialog . $ . dialog . $ . overlay . addEventListener ( 'vaadin-overlay-open' , ( ) => {
581- this . $ . linkUrl . focus ( ) ;
582- } ) ;
583-
584590 const editorContent = editor . querySelector ( '.ql-editor' ) ;
585591
586592 editorContent . setAttribute ( 'role' , 'textbox' ) ;
@@ -632,6 +638,20 @@ class RichTextEditor extends ElementMixin(ThemableMixin(PolymerElement)) {
632638 this . _editor . on ( 'selection-change' , this . __announceFormatting . bind ( this ) ) ;
633639 }
634640
641+ /** @protected */
642+ ready ( ) {
643+ super . ready ( ) ;
644+
645+ this . _toolbarConfig = this . _prepareToolbar ( ) ;
646+ this . _toolbar = this . _toolbarConfig . container ;
647+
648+ this . _addToolbarListeners ( ) ;
649+
650+ this . $ . linkDialog . $ . dialog . $ . overlay . addEventListener ( 'vaadin-overlay-open' , ( ) => {
651+ this . $ . linkUrl . focus ( ) ;
652+ } ) ;
653+ }
654+
635655 /** @private */
636656 _prepareToolbar ( ) {
637657 const clean = Quill . imports [ 'modules/toolbar' ] . DEFAULTS . handlers . clean ;
0 commit comments