slab / quill

Quill is a modern WYSIWYG editor built for compatibility and extensibility
https://quilljs.com
BSD 3-Clause "New" or "Revised" License
42.3k stars 3.31k forks source link

Custom toolbar: buttons mouse clicks get broken if Quill is re-instantiated #4237

Open ViktorZhurbin opened 1 month ago

ViktorZhurbin commented 1 month ago

When Quill editor with a custom toolbar is re-instantiated, toolbar buttons get new event listeners added on top of each other, breaking mouse click behaviour.

In our setup, modules need to be updated based on user preferences, which requires re-instantiating Quill, afaik. I opened #4234 to check if it can be avoided, but this current issue seems like a separate bug.

My guess is that since these listeners are added as anonymous functions they are added each time editor is instantiated, rather than being ignored (reference)

Steps for Reproduction

Here's a demo

https://github.com/slab/quill/assets/34838167/ebf4de7c-a2d0-4e34-ba4e-063bbdcfae91

  1. Visit quilljs playground
  2. Click "Re-create" button
  3. Try to mouse-click any formatting button in toolbar
  4. Check event listeners in dev tools

Expected behavior: Format buttons work as usual

Actual behavior: Format buttons can't be toggled

Platforms: Chrome 125.0.6422.141, MacOS

Version: 2.0.2