Skip to content
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

[Feature request]: Remove costly repeated HostListeners on document:mousedown #588

Open
jneuhaus20 opened this issue Dec 5, 2024 · 0 comments

Comments

@jneuhaus20
Copy link

Description

Use a utility method to register a single mousedown listener for the entire library and have component instances subscribe as needed.

Problem Statement/Justification

The repeated @HostListener('document:mousedown', ['$event']) hamper performance considerably.

In my scenario, I display a component for each item in a list from an API. A single ngx-editor instance in my setup has 5 bindings: two for ColorPickerComponent, one for LinkComponent, one for DropdownComponent, and one for ImageComponent. As the number of entries in the list increases, the performance of the whole site slows to a crawl. With 200 items, Chrome hangs for 4-5 seconds while handling the mousedown event, even when clicking on a non-interactive background region.

There are some techniques to get around this, but they involve changing app architecture, e.g. to use virtual scrolling or paging to limit the number of components in the DOM at once, which is not easy or even always an option.

An alternative solution could be to try focusout instead, which might limit the event handlers invoked to only the relevant components.

Additional Information

I'm using ngx-editor 17.5.4 and Angular 18.2 with zone.js. Haven't tried with zoneless.

The issue is also referenced in this StackOverflow article: Detect click outside Angular component with possible solutions.

Willing to submit a PR?

No

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

No branches or pull requests

1 participant