From 88faf5bba907522d0541f9a8944d3acd16e5b8e0 Mon Sep 17 00:00:00 2001 From: Pas <74743263+Pasithea0@users.noreply.github.com> Date: Wed, 25 Feb 2026 13:11:57 -0700 Subject: [PATCH] Revert "wait untill subtitles are loaded before picking one for reenabling" This reverts commit 8d8d4659dbd893ca6355115e0a9279b5e0f4cdb5. --- src/components/player/hooks/useCaptions.ts | 7 --- .../player/hooks/useInitializePlayer.ts | 51 +++---------------- 2 files changed, 7 insertions(+), 51 deletions(-) diff --git a/src/components/player/hooks/useCaptions.ts b/src/components/player/hooks/useCaptions.ts index decf365f..7d51475c 100644 --- a/src/components/player/hooks/useCaptions.ts +++ b/src/components/player/hooks/useCaptions.ts @@ -24,9 +24,6 @@ export function useCaptions() { const setIsOpenSubtitles = useSubtitleStore((s) => s.setIsOpenSubtitles); const captionList = usePlayerStore((s) => s.captionList); - const isLoadingExternalSubtitles = usePlayerStore( - (s) => s.isLoadingExternalSubtitles, - ); const getHlsCaptionList = usePlayerStore((s) => s.display?.getCaptionList); const source = usePlayerStore((s) => s.source); const selectedCaption = usePlayerStore((s) => s.caption.selected); @@ -188,9 +185,6 @@ export function useCaptions() { useEffect(() => { if (!selectedCaption) return; - // Don't clear while external subtitles are still loading - the caption might appear - if (isLoadingExternalSubtitles) return; - // Skip validation for custom/pasted captions that aren't in the caption list const isCustomCaption = selectedCaption.id === "custom-caption" || @@ -232,7 +226,6 @@ export function useCaptions() { setCaption, selectCaptionById, currentTranslateTask, - isLoadingExternalSubtitles, ]); return { diff --git a/src/components/player/hooks/useInitializePlayer.ts b/src/components/player/hooks/useInitializePlayer.ts index 5f10caf5..f867c803 100644 --- a/src/components/player/hooks/useInitializePlayer.ts +++ b/src/components/player/hooks/useInitializePlayer.ts @@ -1,7 +1,6 @@ -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef } from "react"; import { usePlayerStore } from "@/stores/player/store"; -import { useSubtitleStore } from "@/stores/subtitles"; import { useVolumeStore } from "@/stores/volume"; import { useCaptions } from "./useCaptions"; @@ -25,51 +24,15 @@ export function useInitializeSource() { () => (source ? JSON.stringify(source) : null), [source], ); - const captionList = usePlayerStore((s) => s.captionList); - const isLoadingExternalSubtitles = usePlayerStore( - (s) => s.isLoadingExternalSubtitles, - ); - const getHlsCaptionList = usePlayerStore((s) => s.display?.getCaptionList); - const enabled = useSubtitleStore((s) => s.enabled); const { selectLastUsedLanguageIfEnabled } = useCaptions(); - // Trigger re-run when HLS tracks may have loaded (they load after manifest) - const [hlsRetryTrigger, setHlsRetryTrigger] = useState(0); - const hasRetriedForSourceRef = useRef(null); + // Only select subtitles on initial load, not when source changes + const hasInitializedRef = useRef(false); useEffect(() => { - if (!sourceIdentifier || !enabled) return; - - // Wait for external subtitles to finish loading before selecting - // This ensures we have the full caption list (provider + external) before picking - if (isLoadingExternalSubtitles) return; - - const captions = - captionList.length > 0 ? captionList : (getHlsCaptionList?.() ?? []); - if (captions.length === 0) { - // For HLS sources, tracks may load after manifest - retry once per source - const alreadyRetried = - hasRetriedForSourceRef.current === sourceIdentifier; - if (source?.type === "hls" && !alreadyRetried) { - hasRetriedForSourceRef.current = sourceIdentifier; - const retryTimer = setTimeout( - () => setHlsRetryTrigger((n) => n + 1), - 2000, - ); - return () => clearTimeout(retryTimer); - } - return; + if (sourceIdentifier && !hasInitializedRef.current) { + hasInitializedRef.current = true; + selectLastUsedLanguageIfEnabled(); } - - selectLastUsedLanguageIfEnabled(); - }, [ - sourceIdentifier, - source?.type, - enabled, - isLoadingExternalSubtitles, - captionList, - getHlsCaptionList, - selectLastUsedLanguageIfEnabled, - hlsRetryTrigger, - ]); + }, [sourceIdentifier, selectLastUsedLanguageIfEnabled]); }