Skip to content

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.
Copy link
Contributor

@usantos-at-wiris usantos-at-wiris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the suggestion!

@carla-at-wiris
Copy link
Contributor

Closes #1111

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.

5 participants