Skip to content

fix: stop leaking event listeners #1059

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bendemboski
Copy link

Description

These static methods were storing the event listener callbacks on this, which refers to the (singleton) class itself. This meant that if multiple plugin instances existed at the same time (multiple editors on the same page), the second one would overwrite the stored event listeners for the first one, preventing the first one from actually removing the event listeners (and making it remove the second plugin's event listeners, potentially breaking its functionality).

So instead, associate the event listeners with their target via a Map so multiple plugin instances can coexist.

Also, at least in the CKEditor5 plugin, Util.addElementEvents was getting called twice during initialization, so make sure Util.addElementEvents removes any existing event handlers before adding the "new" ones.

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project ( Run yarn lint to check)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • New and existing unit tests pass locally with my changes

How should be tested? (Manual or Automated Tests)

  • Manual tests: I have tested this changes manually.

These static methods were storing the event listener callbacks on `this`, which refers to the (singleton) class itself. This meant that if multiple plugin instances existed at the same time (multiple editors on the same page), the second one would overwrite the stored event listeners for the first one, preventing the first one from actually removing the event listeners (and making it remove the second plugin's event listeners, potentially breaking its functionality).

So instead, associate the event listeners with their target via a `Map` so multiple plugin instances can coexist.

Also, at least in the CKEditor5 plugin, `Util.addElementEvents` was getting called twice during initialization, so make sure `Util.addElementEvents` removes any existing event handlers before adding the "new" ones.
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

Successfully merging this pull request may close these issues.

1 participant