Skip to content

fix: Patch Memory Leaks#1273

Open
R-Delfino95 wants to merge 3 commits intomuxinc:mainfrom
R-Delfino95:fix/memory-leaks
Open

fix: Patch Memory Leaks#1273
R-Delfino95 wants to merge 3 commits intomuxinc:mainfrom
R-Delfino95:fix/memory-leaks

Conversation

@R-Delfino95
Copy link
Contributor

@R-Delfino95 R-Delfino95 commented Mar 12, 2026

Description

This PR addresses specific edge cases in media-controller that were not covered in previous updates. The goal is to handle a few remaining cleanup tasks and state ownership issues identified after #1261.

Changes:

  • Shortcut Dialog Cleanup: Fixed an issue where the shortcuts dialog was not being removed from the DOM/state on teardown.
  • MediaStore stateOwners: Added logic to ensure stateOwners are cleared from the mediaStore when the controller is disconnected.
  • media-time-range Animation: Added an explicit stop call to the animation in disconnectedCallback() instead of using toggleRangeAnimation().

    Note: This was added to force the stop on disconnect, but I'd appreciate a second look to see if this is actually redundant or necessary.

Related Issues

Relates to Issue #1235
Follow-up to PR #1261

Testing Instructions

  1. General Regression: Can be verified using the same environment/steps as PR fix: Patch Memory Leaks #1261.
  2. Full Flow: To test the integration from mux-player-react, see the example in PR #1285.
  3. Specific Scenarios:
    • Trigger the shortcuts dialog and verify it's destroyed when the player/controller is unmounted.
    • Check that stateOwners are no longer present in mediaStore after disposal.
    • Confirm media-time-range animations cease correctly upon component disconnection.

Note

Medium Risk
Moderate risk because it changes teardown behavior by explicitly clearing MediaStore-owned element references and removing UI elements, which could affect re-mount/reconnect flows if any code relies on prior state persisting.

Overview
Fixes several teardown-related memory leaks by strengthening disconnectedCallback() cleanup across components.

media-controller now clears MediaStore “state owner” references (media/fullscreen/document elements) on disconnect and explicitly removes the keyboard shortcuts dialog from the DOM. media-time-range stops its RangeAnimation directly on disconnect, and media-container/media-chrome-menu reset pending/retained internal references (#isResizePending, focus/invoker pointers) to avoid lingering callbacks and DOM references.

Written by Cursor Bugbot for commit e9595a4. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Mar 12, 2026

@R-Delfino95 is attempting to deploy a commit to the Mux Team on Vercel.

A member of the Team first needs to authorize it.

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 88.23529% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.62%. Comparing base (3ea80df) to head (9dcb38b).
⚠️ Report is 281 commits behind head on main.

Files with missing lines Patch % Lines
src/js/media-controller.ts 73.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1273      +/-   ##
==========================================
- Coverage   78.55%   73.62%   -4.94%     
==========================================
  Files          59       56       -3     
  Lines       11080    13857    +2777     
  Branches        0      785     +785     
==========================================
+ Hits         8704    10202    +1498     
- Misses       2376     3622    +1246     
- Partials        0       33      +33     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@snyk-io
Copy link

snyk-io bot commented Mar 12, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@R-Delfino95 R-Delfino95 marked this pull request as ready for review March 13, 2026 19:03
@R-Delfino95 R-Delfino95 requested review from a team and heff as code owners March 13, 2026 19:03
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

this.#mediaStore?.dispatch({
type: 'fullscreenelementchangerequest',
detail: undefined,
});
Copy link

Choose a reason for hiding this comment

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

Fullscreen element state owner not restored on reconnect

High Severity

The new fullscreenelementchangerequest dispatch with undefined in disconnectedCallback clears the fullscreenElement state owner, but connectedCallback has no matching dispatch to restore it. The #mediaStore is never nulled on disconnect, so #setupDefaultStore() won't re-run on reconnect. Compare with documentelementchangerequest, which is restored in connectedCallback with document, and mediaelementchangerequest, which is restored via mediaSetCallback. After a disconnect/reconnect cycle, fullscreenElement remains undefined in the store, breaking fullscreen functionality.

Additional Locations (1)
Fix in Cursor Fix in Web

this.#mediaStore?.dispatch({
type: 'mediaelementchangerequest',
detail: undefined,
});
Copy link

Choose a reason for hiding this comment

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

Redundant mediaelementchangerequest dispatch in disconnectedCallback

Low Severity

The mediaelementchangerequest dispatch with undefined is redundant. super.disconnectedCallback() on line 471 already triggers mediaUnsetCallback, which dispatches the exact same action (as seen in mediaUnsetCallback at line 545-548). This duplicate dispatch does no harm but adds unnecessary noise to the teardown logic.

Fix in Cursor Fix in Web

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