yuku / textcomplete

Autocomplete for HTMLTextAreaElement and more.
https://yuku.takahashi.coffee/textcomplete/
MIT License
1.74k stars 303 forks source link

Leaking Event Handler #287

Closed jlukic closed 4 years ago

jlukic commented 8 years ago

There's currently a bubbled event being watched on document that appears to be bound to document regardless of whether a textcomplete component is initialized.

Attaching an event handler on every bubbled click event is fairly expensive. This most likely should be part of the components initialize and destroy method, so that it doesn't continue to evaluate on every click event in your site/app.

To make sure its attached once across components you'll most likely need to use some novel strategy, but it could be accomplished using something like unique ids, or namespaced events.

yuku commented 8 years ago

Hi @jlukic, thanks for opening the issue.

I agree that global click event handler costs a bit but I'm not sure it is worth optimized. Does it cause performance issues in your app?

jlukic commented 8 years ago

I'm working on a single page app with something like 50+ distinct pages. Only a few of them use the textcomplete component, however all click events on all pages fire the textcomplete document event handler.

There's no specific issue with the event handler performing poorly, however the design might cause memory issues. The event handler carries a reference to dropdownViews which prevents it from being garbage collected by the browser.