Skip to content

fix: Added a warning when tracks are being added before player init#1317

Open
spuppo-mux wants to merge 1 commit intomuxinc:mainfrom
spuppo-mux:fix/add_warning_when_adding_tracks_early
Open

fix: Added a warning when tracks are being added before player init#1317
spuppo-mux wants to merge 1 commit intomuxinc:mainfrom
spuppo-mux:fix/add_warning_when_adding_tracks_early

Conversation

@spuppo-mux
Copy link
Copy Markdown
Contributor

@spuppo-mux spuppo-mux commented Apr 21, 2026

Closes https://github.com/muxinc/devextravaganza/issues/215

Relates to a behavior we often see (mainly on Safari) that adding a track to the player element before it initializes, causes playback to buffer indefinitely. For example https://github.com/muxinc/devextravaganza/issues/215.

While this PR does not fix the issue, it adds a warning so this behavior is easier to identify.

An example where this could happen is if on React a user were to write this it would log a warning:

const Player = (props) => {
    return (<MuxPlayer
        {...props}
        ref={(instance) => {
            instance?.addChapters(props.chapters);
            props.ref.current = instance;
        }
    />)
}

To address this they should do something like this:

const Player = (props) => {
    return (<MuxPlayer
        {...props}
        ref={(instance) => {
            if (instance) {
                const handler = () => instance.addChapters(muxChapters ?? []);
                instance.addEventListener(
                    "loadedmetadata", 
                    () => instance.addChapters(props.chapters), 
                    { once: true }
                );
            }
            
            props.ref.current = instance;
        }
    />)
}

Note

Low Risk
Low risk: adds console warnings only; behavior and data flow for chapters/cue points remain unchanged aside from extra logging that could be noisy in some apps.

Overview
Adds a guard in MuxVideoBaseElement.addCuePoints() and addChapters() to console.warn when these are called before the media element has a currentSrc, nudging callers to wait for initial load (e.g., loadstart). No functional change to how cue points/chapters are added beyond emitting the warning.

Reviewed by Cursor Bugbot for commit ce3c216. Bugbot is set up for automated code reviews on this repo. Configure here.

@spuppo-mux spuppo-mux requested a review from a team as a code owner April 21, 2026 21:31
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 21, 2026

@spuppo-mux is attempting to deploy a commit to the Mux Team on Vercel.

A member of the Team first needs to authorize it.

@snyk-io
Copy link
Copy Markdown

snyk-io Bot commented Apr 21, 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.

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