Skip to content

Commit

Permalink
Revert "fix: clean up listeners in quill editor when the rich-text-ed…
Browse files Browse the repository at this point in the history
…itor is detached (#6489) (#6498)"

This reverts commit 4dd6ee5.
  • Loading branch information
web-padawan committed Sep 18, 2023
1 parent 0027e59 commit 00564b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 52 deletions.
35 changes: 11 additions & 24 deletions packages/rich-text-editor/src/vaadin-rich-text-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,6 @@ class RichTextEditor extends ElementMixin(ThemableMixin(PolymerElement)) {
}
}

/** @protected */
disconnectedCallback() {
super.disconnectedCallback();
this._editor.emitter.removeAllListeners();
this._editor.emitter.listeners = {};
}

/** @private */
__setDirection(dir) {
// Needed for proper `ql-align` class to be set and activate the toolbar align button
Expand All @@ -554,14 +547,18 @@ class RichTextEditor extends ElementMixin(ThemableMixin(PolymerElement)) {
}

/** @protected */
connectedCallback() {
super.connectedCallback();
ready() {
super.ready();

const editor = this.shadowRoot.querySelector('[part="content"]');
const toolbarConfig = this._prepareToolbar();
this._toolbar = toolbarConfig.container;

this._addToolbarListeners();

this._editor = new Quill(editor, {
modules: {
toolbar: this._toolbarConfig,
toolbar: toolbarConfig,
},
});

Expand All @@ -573,6 +570,10 @@ class RichTextEditor extends ElementMixin(ThemableMixin(PolymerElement)) {
this.__patchFirefoxFocus();
}

this.$.linkDialog.$.dialog.$.overlay.addEventListener('vaadin-overlay-open', () => {
this.$.linkUrl.focus();
});

const editorContent = editor.querySelector('.ql-editor');

editorContent.setAttribute('role', 'textbox');
Expand Down Expand Up @@ -603,20 +604,6 @@ class RichTextEditor extends ElementMixin(ThemableMixin(PolymerElement)) {
this._editor.on('selection-change', this.__announceFormatting.bind(this));
}

/** @protected */
ready() {
super.ready();

this._toolbarConfig = this._prepareToolbar();
this._toolbar = this._toolbarConfig.container;

this._addToolbarListeners();

this.$.linkDialog.$.dialog.$.overlay.addEventListener('vaadin-overlay-open', () => {
this.$.linkUrl.focus();
});
}

/** @private */
_prepareToolbar() {
const clean = Quill.imports['modules/toolbar'].DEFAULTS.handlers.clean;
Expand Down
28 changes: 0 additions & 28 deletions packages/rich-text-editor/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,32 +929,4 @@ describe('rich text editor', () => {
);
});
});

describe('listener clean up', () => {
it('should not have active listeners once detached', () => {
expect(editor.emitter).to.not.equal(null);
expect(editor.emitter._events).to.not.be.empty;
expect(editor.emitter._eventsCount).to.greaterThan(0);
expect(editor.emitter.listeners).to.not.be.empty;

rte.parentNode.removeChild(rte);

expect(editor.emitter._events).to.be.empty;
expect(editor.emitter._eventsCount).to.be.equal(0);
expect(editor.emitter.listeners).to.be.empty;
});

it('should have the listeners when removed and added back again', () => {
const parent = rte.parentNode;

parent.removeChild(rte);
parent.appendChild(rte);

// Previous `editor` reference is now stale as a new editor is created in the connectedCallback
expect(rte._editor.emitter).to.not.equal(null);
expect(rte._editor.emitter._events).to.not.be.empty;
expect(rte._editor.emitter._eventsCount).to.greaterThan(0);
expect(rte._editor.emitter.listeners).to.not.be.empty;
});
});
});

0 comments on commit 00564b8

Please sign in to comment.