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

Event listener leak in ReorderableRow and ReorderableColumn #11357

Closed
woppa684 opened this issue Mar 30, 2022 · 2 comments
Closed

Event listener leak in ReorderableRow and ReorderableColumn #11357

woppa684 opened this issue Mar 30, 2022 · 2 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@woppa684
Copy link

woppa684 commented Mar 30, 2022

I'm submitting a ... (check one with "x")

[x ] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

ReorderableRow and ReorderableColumn have bindEvents and undbindEvents methods. The unbindEvents for ReorderableRow is never called and the one for ReorderanleColumn is called in its ngOnDestroy. Not calling the one for the row already seems like a bug to me, but the main problem is in the implementation of both the unbind methods. To illustrate this, a small excerpt from one of the bind functions:

this.mouseDownListener = this.onMouseDown.bind(this);
this.el.nativeElement.addEventListener('mousedown', this.mouseDownListener);

And the corresponding unbind:

if (this.mouseDownListener) {
document.removeEventListener('mousedown', this.mouseDownListener);
this.mouseDownListener = null;
}

As can be seen, the listeners are registered on the nativeElement but removed from the document (where the listener was never registered), leaving the event listeners on the nativeElement behind. One could argue that, as the element is removed also the listeners get cleaned up, but this does not work for every usecase. Also, it seems that the idea was to have unbind methods, so let's make sure that they're correct and used :)

As mentioned, ReorderableColumn does have an ngOnDestroy (see below) but ReorderableRow has not.

ngOnDestroy() {
this.unbindEvents();
}

@yigitfindikli yigitfindikli added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Mar 30, 2022
@yigitfindikli yigitfindikli self-assigned this Mar 30, 2022
@yigitfindikli yigitfindikli added this to the 13.3.2 milestone Mar 30, 2022
@woppa684
Copy link
Author

woppa684 commented Mar 30, 2022

@yigitfindikli
Ok, so this fix adds the ngOnDestroy for ReorderableRow, what about the wrong unbind implementation? :) I don't think this issue should have been closed already. I think we can agree that adding an event listener to one element and removing it from somewhere else does not work, right?

@woppa684
Copy link
Author

@yigitfindikli I could also make a PR if you prefer, but it seems trivial to just replace the document references to this.el.nativeElement in the unbindEvents methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

2 participants