Skip to content

Svelte 5: is removeEventListener necessary for bindings? #11279

Closed
@Rich-Harris

Description

@Rich-Harris

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions