Skip to content

fix: guard HLS load target and PiP null video - #1859

Open
Steve0x2a wants to merge 1 commit into
vidstack:mainfrom
Steve0x2a:fix/hls-unmount-pip-null
Open

fix: guard HLS load target and PiP null video#1859
Steve0x2a wants to merge 1 commit into
vidstack:mainfrom
Steve0x2a:fix/hls-unmount-pip-null

Conversation

@Steve0x2a

Copy link
Copy Markdown

Related:

Fixes #1771. Thanks @rbao for the report and for identifying both sites.

Description:

Unmounting <MediaPlayer> while the HLS provider chunk is still dynamically importing can construct HLSProvider with a nulled loader.target. canUsePictureInPicture(null) then returns true because !video?.disablePictureInPicture is true when video is null, so VideoPictureInPicture is created on null and EventsController.add throws TypeError: Cannot read properties of null (reading 'addEventListener').

This is the same predicate class as #989 (canUseVideoPresentation); that fix did not cover picture-in-picture.

  • HLSProviderLoader.load now snapshots const target = this.target before await import('./provider') and constructs with that element, or bails if it is null.
  • canUsePictureInPicture requires a real video element.

Ready?

Yes.

Anything Else?

Unit tests in jsdom cover both sites (preferred over Slow 4G E2E). Scope is #1771 only.

Review Process:

  • pnpm -F vidstack exec vitest --run src/utils/support.test.ts src/providers/hls/loader.test.ts
  • canUsePictureInPicture(null) is false when document.pictureInPictureEnabled is true
  • Clearing loader.target during the HLS provider import no longer throws

Snapshot the HLS loader target before the provider dynamic import so
an unmount cannot construct HLSProvider with null. Require a real
video element in canUsePictureInPicture, matching vidstack#989.

Fixes vidstack#1771

Signed-off-by: Yi Zhan <stevesough@gmail.com>
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.

Unmounting <MediaPlayer> during HLS chunk load throws null.addEventListener

1 participant