wobsoriano / lexical-vue

An extensible Vue 3 web text-editor based on Lexical.
https://lexical-vue.vercel.app/
MIT License
251 stars 30 forks source link

Fix checkbox click listeners again #24

Closed zswaff closed 1 year ago

zswaff commented 1 year ago

Background

The fix that I implemented in #20 helped but did not fix all cases. Because removeEventListener requires the exact same function to be passed to it that was originally passed to addEventListener, calling unregister from a different editor doesn't do anything, leaving the listeners. This is a memory leak but more importantly it means that if you later reregister listeners, there are an even number, and checklist clicks again do not work.

Repro

  1. Make one editor and then another, each with the checklist plugin
  2. Remove the first one, then the second one (the second one tries to clean up the listeners that the first one registered, which doesn't work)
  3. Add another editor (which re-adds listeners, for a total of two) and observe that checklist boxes don't change (or, rather, change twice) on click

Fix

This fix uses the same patterns but simplifies the listenerManager signature and ensures that the final unregistration calls the reverse of the original registration.

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 16, 2023 9:10pm
lexical-vue-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 16, 2023 9:10pm