Skip to content

fix: allow textTracks redefinition on repeated HLS source-set - #1086

Merged
adimiz1 merged 1 commit into
masterfrom
fix/hls-texttracks-redefine-on-source-fallback
Sep 14, 2026
Merged

adimiz1 merged 1 commit into
masterfrom
fix/hls-texttracks-redefine-on-source-fallback

Conversation

@adimiz1

@adimiz1 adimiz1 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Customer reported TypeError: Cannot redefine property: textTracks and dead playback when a second HLS source is set on the same player/element — e.g. hls/h265 returns 400 and the app falls back to hls/h264 on the same instance.
  • Root cause: Html5HlsJS() calls Object.defineProperty(el, 'textTracks', {...}) on every source-set, but configurable was never set, so it defaults to false. The second call throws before hls.attachMedia()/hls.loadSource() ever run, so the fallback source never attaches.
  • Fix: add configurable: true to that descriptor.

Trade-off

Adding configurable: true removes a fail-fast guard. If some future refactor ever causes Html5HlsJS() to run twice on the same el without going through video.js's normal dispose-first lifecycle (Tech.prototype.setSource → disposeSourceHandler() → hls.destroy() → new source handler), it will now silently reconfigure the property instead of throwing where it would previously have been caught in testing/monitoring. Verified via video.js core that the current, real call pattern always disposes the old source handler and reuses the same tech object before creating the new one — so the getter closure is functionally identical before and after redefinition, and this trade-off does not present a risk in the actual call path today. It's a latent risk for a different, currently-hypothetical bug class only.

Verification

  • Reproduced live in-browser against the demo page (docs/adaptive-streaming.html): confirmed the exact reported stack trace (Html5HlsJS → handleSource → Tech.setSource → Player.src_) with the fix reverted, and confirmed clean playback with the fix applied.
  • Added test/unit/videojs-contrib-hlsjs-texttracks.test.js as a permanent regression test, exercising the real module via a captured HlsSourceHandler reference (mocking only hls.js, irrelevant to this bug).

Out of scope (flagged separately, not fixed here)

  • el.addEventListener('error', ...) is re-added on every Html5HlsJS() call but never removed by dispose() — a pre-existing stale-listener leak on repeated source-sets, independent of this bug.
  • Local e2e (test/adaptive-streaming.test.js via jest-puppeteer) is currently broken in this checkout for unrelated reasons (jest-environment-puppeteer export-shape mismatch, page.waitFor removed in the installed Puppeteer version) — confirmed the pre-existing tests in that file also fail in isolation, unrelated to this change.

Test plan

  • Reproduced the bug locally, verified the exact reported error
  • Applied fix, confirmed second HLS source-set no longer throws, live in browser
  • Added unit regression test (test/unit/videojs-contrib-hlsjs-texttracks.test.js)
  • CI unit test run (local vitest run blocked by an unrelated vite/vitest version mismatch in this checkout)

Object.defineProperty defaults configurable to false for accessor
descriptors. Html5HlsJS() redefines el.textTracks on every source-set,
so a second HLS source on the same tech/element (e.g. hls/h265 ->
hls/h264 fallback after a 400) threw "Cannot redefine property:
textTracks" before hls.attachMedia()/loadSource() ever ran, killing
playback silently.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@adimiz1
adimiz1 requested a review from a team as a code owner September 14, 2026 05:48
@netlify

netlify Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cld-vp-esm-pages ready!

Name Link
🔨 Latest commit ccaf1bf
🔍 Latest deploy log https://app.netlify.com/projects/cld-vp-esm-pages/deploys/6aa78ac3cc9a8300086f6d2a
😎 Deploy Preview https://deploy-preview-1086--cld-vp-esm-pages.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cld-video-player ready!

Name Link
🔨 Latest commit ccaf1bf
🔍 Latest deploy log https://app.netlify.com/projects/cld-video-player/deploys/6aa78ac37345c30008ee7fa7
😎 Deploy Preview https://deploy-preview-1086--cld-video-player.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@tsi tsi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

@adimiz1
adimiz1 merged commit 4a0e328 into master Sep 14, 2026
10 checks passed
@adimiz1
adimiz1 deleted the fix/hls-texttracks-redefine-on-source-fallback branch September 14, 2026 07:15
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.

3 participants