-
Notifications
You must be signed in to change notification settings - Fork 22
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
Introduce dispose method #227
Comments
Hi @MarketingPip I think I know what's your suggestion but could you please explain more about your idea? |
@hueitan - I am having to reinit this component to detect new links added to DOM. Rather than you guys using Intersection Observer API. I suggest you add a I have peaked through the code - and suggest doing clearAllEventListener()
element.remove()
// set any references to the element etc / things stored to null.. in events. I could possibly make a PR - tho I will be honest I didn't have much hope I was going to get a reply on this repo. Seeing the bundle size issue still being open from years ago! |
Thanks for the feedback @MarketingPip We previously worked on a We have a milestone to rewrite the library with a more structured solution instead of the current vanilla JavaScript implementation, but I don't have an update on the progress or deadline at the moment. Pull Requests are welcome. As you may know, we use |
@hueitan - can you send me the pull request / the exact issue into the 3rd party library. For wikipedia etc - I would be willing to take some time to make a PR to nip this in the butt. |
This is the closed PR #191 and ticket https://phabricator.wikimedia.org/T363468 There isn't much you can look at for the event listener issues from these links, I would recommend you make the changes based on the current codebase. |
@hueitan - then I am confused... There should be no issue with removing the element / and all event listeners when not needed. By using this code. clearAllEventListener()
element.remove()
// set any references to the element etc / things stored to null.. |
@MarketingPip, I understand your point now about removing elements after calling In some scenarios, we don't completely remove the DOM elements because we reuse them to bind new events. For instance, when closing a preview and then opening a new one, the same element might be used again. Because of this, we can’t just remove the element outright within That’s also why we introduced the idea of refactoring—to unify how we handle event listeners across the board. This way, we can ensure a consistent approach without running into these kinds of challenges. For now, I don’t see this as a major issue, since modern browsers are quite efficient at managing memory. |
@hueitan - I get this... But again.. For new links I append to the DOM. Links DO not get detected. I have to reinit the component - which adds MULTIPLE event listeners - causing a leakage in memory..... So it would be ideal to COMPLETELY remove the component / event listeners WHEN I do not need this.............. As for your last comment. Browsers are NOT efficient for managing memory. |
https://phabricator.wikimedia.org/T380988 @MarketingPip Thanks for the explanation and I see this a problem now when we reinit() on the page I have the several ideas for the fix
|
@hueitan - better idea. Remove all event listeners by default on init - so if called again by accident. No extra / duplicate event handlers are added. Then add event listeners. Plus add a dispose method - as this should be a standard with any component (even tho I am guilty of not doing this). |
A dispose method would be nice for this using
The text was updated successfully, but these errors were encountered: