hls-video-element: HLS instances are initialized on disconnected elements during React Suspense retries
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 65/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, react
Research direction
Start by reading the load() implementation in the hls-video-element code and trace how custom element connection and destruction are handled. Reproduce the race with React Suspense or repeated load() calls, then verify that abandoned or disconnected elements do not create HLS instances while a valid load still starts playback.
Written by the indexing model from the issue text.
Description
When using hls-video-element with React Suspense, multiple HLS instances can be created for custom elements that never become connected to the DOM.This appears to be caused by asynchronous initialization in load().
The current implementation calls #destroy(), then awaits Promise.resolve() before creating a new HLS instance:
async load() {
const isFirstLoad = !this.api;
this.#destroy();
if (!this.src) return;
if (Hls.isSupported()) {
await Promise.resolve();
this.api = new Hls({
liveDurationInfinity: true,
autoStartLoad: false,
...this.config,
});
this.api.loadSource(this.src);
this.api.attachMedia(this.nativeEl);
}
}
During the asynchronous gap, the element can be disconnected from the DOM or another load() invocation can occur. There is currently no check to ensure that the element is still connected or that the pending load operation is still valid before creating the HLS instance.
As a result, an HLS instance may be created for an element that React has already abandoned.
example sandbox: https://codesandbox.io/p/sandbox/2zlv3c
or simply render lazy components together in one Suspense wrapper
import { Suspense, lazy, useEffect, useState } from 'react';
import HlsVideo from 'hls-video-element/react';
<Suspense fallback={<div>loading…</div>}>
<HlsVideo src={SRC} preload="auto" muted style={{ width: 320 }} autoplay={false} />
<LazySiblingA />
<LazySiblingB />
<LazySiblingC />
</Suspense>
in the network tab you can also see 5 request instances for one video:
note: This race condition can occur without React Suspense. Suspense is just one way to expose it.
- Dominant language
- JavaScript
- Stars
- 266
- Forks
- 53
- Avg merge
- 13m
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Similar issues
-
[19.0] pos_sale: settling an order with a 0 down payment line crashes (reading 'reward_id') and leaves a wrong amount duePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
verified whatsapp
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 6 days
-
Difficulty 1/5 Under an hour Newbie friendliness 83/100
Maintainers usually reply within 1 day