fix: defer load() until connected to prevent metadata race on first Mux Data beacon#1326
Open
R-Delfino95 wants to merge 4 commits intomuxinc:mainfrom
Open
fix: defer load() until connected to prevent metadata race on first Mux Data beacon#1326R-Delfino95 wants to merge 4 commits intomuxinc:mainfrom
R-Delfino95 wants to merge 4 commits intomuxinc:mainfrom
Conversation
|
@R-Delfino95 is attempting to deploy a commit to the Mux Team on Vercel. A member of the Team first needs to authorize it. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e4944fc. Configure here.
luwes
approved these changes
May 8, 2026
luwes
requested changes
May 8, 2026
Contributor
luwes
left a comment
There was a problem hiding this comment.
actually could we solve this without preventing the load() to go through when not connected?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
Fixes #1199
When
<mux-player>(or<mux-video>) is created programmatically and attributes are set before the element is appended to the DOM — with any async yield between attribute setting and appendChild (e.g. await Promise.resolve(), React's async reconciliation, Next.js rendering, etc.) — the first Mux Data analytics beacon is sent with an incorrectvideo_id.Root cause:
mux-video.#requestLoad()schedulesload()in a microtask viaawait Promise.resolve(). Under the following sequence, that microtask fires beforemux-player.connectedCallbackhas a chance to propagate metadata-* attributes to the inner<mux-video>:metadata-* attributes are not in mux-video's observedAttributes. They are read lazily from the element's own DOM attributes by the metadata getter. Since mux-player's template does not forward metadata-* attributes to the inner , propagation only happens in
mux-player.connectedCallback. Any async gap before appendChild causes the firstmux.monitor()call — which setsvideo_idpermanently for the view — to receive empty metadata. Because video_id is fixed at view start and cannot be corrected retroactively, the beacon is permanently wrong.Fix
Added an
isConnectedguard inside mux-video's#requestLoad()When the element is not yet connected at microtask time, the deferred
load()is skipped. The existingconnectedCallbackalready re-triggers#requestLoad()once the element connects (guarded by!this.#core), soload()runs aftermux-player.connectedCallbackhas propagated metadataNote
Medium Risk
Changes
MuxVideoBaseElementinitialization timing and tracking reload behavior, which can affect when playback-core is initialized and when Mux Data beacons start firing. Risk is limited to element lifecycle edge cases but could impact analytics or autoplay/resume flows if misordered.Overview
Defers
MuxVideoBaseElementload()execution until the element is actually connected (isConnectedguard inside#requestLoad()), preventing the initial Mux Data beacon from firing before parent elements (e.g.mux-player) can propagatemetadata-*attributes.Adjusts
disable-trackingattribute handling to skip unload/reload while disconnected, avoiding a.then()resume path that would run without a correspondingload();connectedCallbackwill re-trigger#requestLoad()once connected.Reviewed by Cursor Bugbot for commit f845ff3. Bugbot is set up for automated code reviews on this repo. Configure here.