fix(web): fix container warning and store lifecycle

This commit is contained in:
Kamil Moskała
2026-03-25 15:41:01 +01:00
parent 41c97080e3
commit 8e8b089ddb
2 changed files with 10 additions and 3 deletions
@@ -61,6 +61,11 @@ class VideoPlayer extends VideoPlayerEvents implements VideoPlayerBase {
this.mediaSession?.disable();
(this.eventEmitter as WebEventEmitter).destroy();
this.clearAllEvents();
// Store destroy calls detach internally — safe here since player is dead
if (this._store?.destroyed === false) {
this._store.destroy();
}
this._store = null;
}
/** @internal */
@@ -21,13 +21,15 @@ const Player = createPlayer({ features: videoFeatures });
* then passes the ready store to the adapter.
*/
function PlayerBridge({ player }: { player: VideoPlayer }) {
const { store } = usePlayerContext();
const { store, container } = usePlayerContext();
const setMedia = useMediaAttach();
useEffect(() => {
if (!container) return;
const video = player.__getMedia();
setMedia?.(video);
const detach = store.attach({ media: video, container: null });
const detach = store.attach({ media: video, container });
player.__setStore(store);
return () => {
@@ -35,7 +37,7 @@ function PlayerBridge({ player }: { player: VideoPlayer }) {
detach?.();
setMedia?.(null);
};
}, [store, player, setMedia]);
}, [store, player, setMedia, container]);
return null;
}