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

allow clrAlertClosedChange to execute before closing the alert #1151

Open
wghglory opened this issue Jan 22, 2024 · 1 comment
Open

allow clrAlertClosedChange to execute before closing the alert #1151

wghglory opened this issue Jan 22, 2024 · 1 comment
Assignees

Comments

@wghglory
Copy link

Summary

In the current implementation, Clarity removes the alert DOM immediately upon closing and then triggers _closedChanged after that. This means that any custom callback wrapped by clrAlertClosedChange runs after the DOM changes.

However, when the alert contains a button or other interactive elements with click event registrations, it's advisable to prevent memory leaks by removing event listeners before removing the DOM.

To achieve this, it is suggested to consider moving this._closedChanged.emit(true); before this.multiAlertService.close(isCurrentAlert); in the alert.ts close function. This adjustment would allow developers to locate the DOM element inside the alert and remove event listeners accordingly.

For a more detailed reference, please review the code in the provided GitHub link: ng-clarity/alert.ts.

By making this change, developers will have the opportunity to manage event listeners and prevent potential memory leaks associated with event registrations on interactive elements within the alert.

@dtsanevmw dtsanevmw self-assigned this Jan 22, 2024
@dtsanevmw
Copy link
Contributor

dtsanevmw commented Jan 30, 2024

Hello @wghglory ,

Even if we emit the closedChange before the service one this._closed = true; is assigned even before that and the *ngIf on the alert is pointing to that. Although if you are holding a reference to an element inside the alert -- you can still remove the listeners. If you don't have a reference to the element but you have added listeners and that element is removed from the DOM -- then the listeners will be removed too.

However if there are still issues with that -- then we can look into something like having events before / after the alert is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants