Repository navigation
fix(hls-video-element): ignore superseded load() calls to avoid leaking an hls.js instance - #261
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
|
@RaphaelFakhri is attempting to deploy a commit to the Mux Team on Vercel. A member of the Team first needs to authorize it. |
…ng an hls.js instance
RaphaelFakhri
force-pushed
the
fix/hls-video-concurrent-load
branch
from
October 22, 2026 12:16
95aaa9b to
05de95b
Compare
Author
|
Rebased onto |
This branch has not been deployed
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.
Fixes the race in
<hls-video>where callingload()more than once before the first call finishes creates more than one hls.js instance.The bug
load()destroys the current instance, then waits one tick withawait Promise.resolve()before it creates a newHls. Whensrcchanges twice in the same tick (for example a framework that setssrcafter the element already has one), both calls destroy nothing, both wait, and both resume. Each one creates anHlsand attaches it to the same media element:Hlsinstance is overwritten inthis.api, so nothing can destroy it later. It keeps loading and buffering.<source>elements are appended to the native element.The change
Each
load()call takes a generation number from#loadId. After eachawait, the call returns if a newerload()has started, so only the most recent call creates a player. The native HLS path (Safari) has the same check.Testing
Added
changing src twice in the same tick creates a single hls.js instancetopackages/hls-video-element/test/test.js. It counts theHlsinstances attached to the element and the<source>elements.eslint *.jsis clean.Note
Low Risk
Targeted concurrency guard around existing load lifecycle; behavior unchanged when src updates are not racing on the same tick.
Overview
Fixes a race in
<hls-video>whensrcchanges multiple times beforeload()finishes its one-tick deferral: overlapping calls could each create an hls.js player, orphan the first instance, and append duplicate<source>elements.load()now bumps a private#loadIdper invocation and bails out after eachawaitif a newer load has started, so only the latestsrcwins on both the hls.js and native Safari paths.Adds a test that sets
srctwice in the same tick and asserts a single attached Hls instance, the final URL, and one<source>.Reviewed by Cursor Bugbot for commit 05de95b. Bugbot is set up for automated code reviews on this repo. Configure here.