Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nochev
Copy link

@nochev nochev commented Sep 26, 2025

Description

This PR fixes a memory leak issue in the TrackButton component.
Currently, TrackButton attaches event listeners to TextTrackList and the player instance, but only removes some of them when the player is disposed. If a TrackButton instance itself is disposed (e.g. when custom text tracks are removed/added dynamically), the listeners remain active, causing stale references and potential leaks.

The issue was noticed when dynamically removing and adding text tracks in CaptionsButton or TrackButton components — old listeners were not cleaned up, leading to unexpected behavior, memory usage growth and errors like main.js:1685 VIDEOJS: ERROR: Error: Invalid target for null#on; must be a DOM node or evented object..

Specific Changes proposed

  • Store references to updateHandler and disposeHandler as private properties (this.updateHandler_, this.disposeHandler_).
  • Override dispose() to:
    • Remove all attached listeners from TextTrackList and the player.
    • Clear the handler references (delete this.updateHandler_, delete this.disposeHandler_).
    • Call super.dispose() afterwards.

Requirements Checklist

  • Feature implemented / Bug fixed
  • Tests are passing (manual verification, no regressions observed)
  • Documentation updated (inline JSDoc for dispose())

Note: Currently using delete this.updateHandler_ for cleanup. If maintainers prefer = null for consistency/performance, I can update accordingly.

@welcome
Copy link

welcome bot commented Sep 26, 2025

💖 Thanks for opening this pull request! 💖

Things that will help get your PR across the finish line:

  • Run npm run lint -- --errors locally to catch formatting errors earlier.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@nochev nochev force-pushed the fix/track-button-listeners-leak branch from 48ad645 to c374ab7 Compare September 26, 2025 12:25
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

Successfully merging this pull request may close these issues.

1 participant