fix: defer load() until connected to prevent metadata race on first Mux Data beacon#1326
Open
R-Delfino95 wants to merge 3 commits intomuxinc:mainfrom
Open
fix: defer load() until connected to prevent metadata race on first Mux Data beacon#1326R-Delfino95 wants to merge 3 commits intomuxinc:mainfrom
R-Delfino95 wants to merge 3 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.
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 initialization timing and reload behavior for
mux-video, which can affect first-play analytics and some playback edge cases around connect/disconnect anddisable-trackingtoggles.Overview
Fixes a race where
MuxVideoBaseElementcould callload()from the#requestLoad()microtask before the element is connected, causing the first Mux Data beacon to start with missingmetadata-*values.#requestLoad()now bails out when!isConnected, relying onconnectedCallback()to re-trigger the load once attached. Relatedly, togglingdisable-trackingno longer unloads/reloads while disconnected to avoid a.then()resume without a correspondingload().Reviewed by Cursor Bugbot for commit 5ebec4a. Bugbot is set up for automated code reviews on this repo. Configure here.