Skip to content

Conversation

@dfritsch
Copy link

@dfritsch dfritsch commented Jun 2, 2025

Updates the binding observer and dispatch logic to always clean up the event listeners.

Without this change, removing an element inside a controller can cause the bindings on that element to be removed but the event listeners are left dangling. Even if the controller is eventually also removed, these events will never be cleaned up, so these elements will remain in memory indefinitely.

Based on the tests, the one downside of this is that if you adjust an event that was set to once and move it to a different order on the element, that action now has a different index so will disconnect the old binding and add a new binding. Previously this would find the old event listener that wasn't properly cleaned up and re-use it, keeping the "once" logic. Actions which are added on top of the existing action would keep the same event, so this still partly works.

clearEventListeners would be passed as true in all cases with this update, so the parameter is removed.

Fixes #838

Updates the binding observer and dispatch logic to always clean up the
event listeners.

Without this change, removing an element _inside_ a controller can cause
the bindings on that element to be removed but the event listeners are
left dangling. Even if the controller is eventually also removed, these
events will never be cleaned up, so these elements will remain in memory
indefinitely.

Based on the tests, the one downside of this is that if you adjust an
event that was set to once and move it to a different order on the element,
that action now has a different index so will disconnect the old binding
and add a new binding. Previously this would find the old event listener
that wasn't properly cleaned up and re-use it, keeping the "once" logic.
Actions which are added on top of the existing action would keep the
same event, so this still partly works.

`clearEventListeners` would be passed as `true` in all cases with this
update, so the parameter is removed.

private disconnectAllActions() {
this.bindings.forEach((binding) => this.delegate.bindingDisconnected(binding, true))
this.bindings.forEach((binding) => this.delegate.bindingDisconnected(binding))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual "fix" is adding true to line 70 above. However, this makes all cases true, so instead the option is removed entirely.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

eventListeners are not removed when removing an element within a controller

1 participant