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

Svelte 5: is removeEventListener necessary for bindings? #11279

Closed
Rich-Harris opened this issue Apr 21, 2024 · 1 comment
Closed

Svelte 5: is removeEventListener necessary for bindings? #11279

Rich-Harris opened this issue Apr 21, 2024 · 1 comment
Milestone

Comments

@Rich-Harris
Copy link
Member

Describe the problem

While reviewing #11271, I noticed that we're calling addEventListener for certain bindings without an accompanying removeEventListener. At first I thought we should probably add the removeEventListener, but then it occurred to me that the event listeners exist for the full lifetime of the element — after it gets removed from the DOM, it should be GC'd along with its event handlers.

Is that true though? Is it safe not to remove event listeners?

Describe the proposed solution

We should do one of two things:

  1. Remove event listeners, if we do in fact need to
  2. More likely, we can remove some redundant removeEventListener calls, making the library a tiny bit leaner

Importance

nice to have

@Rich-Harris Rich-Harris added this to the 5.0 milestone Apr 21, 2024
@dummdidumm
Copy link
Member

It is indeed unnecessary to call removeEventListener in that case, but our code is already optimal with regards to that - no unnecessary calls for any bindings.

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

2 participants