From b40d45cbcb7e3dcbd1f3bbfd4405c92f203ba807 Mon Sep 17 00:00:00 2001 From: chrisk325 Date: Fri, 6 Mar 2026 13:21:47 +0530 Subject: [PATCH 1/5] fix unmount logic edgecases --- src/components/metadata/HeroSection.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/metadata/HeroSection.tsx b/src/components/metadata/HeroSection.tsx index 32743cc9..f56c9dd3 100644 --- a/src/components/metadata/HeroSection.tsx +++ b/src/components/metadata/HeroSection.tsx @@ -1140,10 +1140,12 @@ const HeroSection: React.FC = memo(({ return; } + setTrailerUrl(null); setTrailerLoading(true); setTrailerError(false); setTrailerReady(false); setTrailerPreloaded(false); + startedOnReadyRef.current = false; // Small delay to avoid blocking the UI render timerId = setTimeout(async () => { From 9dfb3aa47450c7813408a7196bf902f68467276c Mon Sep 17 00:00:00 2001 From: chrisk325 Date: Fri, 6 Mar 2026 13:24:02 +0530 Subject: [PATCH 2/5] fix edge cases --- src/components/metadata/HeroSection.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/metadata/HeroSection.tsx b/src/components/metadata/HeroSection.tsx index f56c9dd3..37fd01e2 100644 --- a/src/components/metadata/HeroSection.tsx +++ b/src/components/metadata/HeroSection.tsx @@ -1140,7 +1140,6 @@ const HeroSection: React.FC = memo(({ return; } - setTrailerUrl(null); setTrailerLoading(true); setTrailerError(false); setTrailerReady(false); From 21e5035c9792212989abc27fc70bb3b54e16f25e Mon Sep 17 00:00:00 2001 From: chrisk325 Date: Fri, 6 Mar 2026 13:32:44 +0530 Subject: [PATCH 3/5] minor fix to trailer retry logic --- src/components/metadata/TrailerModal.tsx | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/components/metadata/TrailerModal.tsx b/src/components/metadata/TrailerModal.tsx index b49428e4..856695c1 100644 --- a/src/components/metadata/TrailerModal.tsx +++ b/src/components/metadata/TrailerModal.tsx @@ -159,28 +159,18 @@ const TrailerModal: React.FC = memo(({ const handleVideoError = useCallback((error: any) => { logger.error('TrailerModal', 'Video error:', error); - const errorCode = error?.error?.code; - const isRetryableError = errorCode === -1102 || errorCode === -1009 || errorCode === -1005; - - if (isRetryableError && retryCount < 2) { - logger.info('TrailerModal', `Retrying video load (attempt ${retryCount + 1}/2)`); + if (retryCount < 2) { + logger.info('TrailerModal', `Re-extracting trailer (attempt ${retryCount + 1}/2)`); setRetryCount(prev => prev + 1); - - // Capture current URL before clearing it - setTrailerUrl(current => { - const urlToRestore = current; - setTimeout(() => { - setTrailerUrl(urlToRestore); - }, 500); - return null; // Clear first to force remount - }); + // Re-run full extraction — don't reload the same bad URL + loadTrailer(); return; } - logger.error('TrailerModal', 'Video error after retries or non-retryable:', error); + logger.error('TrailerModal', 'Video error after retries:', error); setError('Unable to play trailer. Please try again.'); setLoading(false); - }, [retryCount]); + }, [retryCount, loadTrailer]); const handleTrailerEnd = useCallback(() => { setIsPlaying(false); From a64d5ac91051c8e51655eaa2b71c86a543d22a37 Mon Sep 17 00:00:00 2001 From: chrisk325 Date: Fri, 6 Mar 2026 13:40:20 +0530 Subject: [PATCH 4/5] fix invalidate cache logic --- src/components/metadata/TrailerModal.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/metadata/TrailerModal.tsx b/src/components/metadata/TrailerModal.tsx index 856695c1..a0d1eeae 100644 --- a/src/components/metadata/TrailerModal.tsx +++ b/src/components/metadata/TrailerModal.tsx @@ -162,7 +162,8 @@ const TrailerModal: React.FC = memo(({ if (retryCount < 2) { logger.info('TrailerModal', `Re-extracting trailer (attempt ${retryCount + 1}/2)`); setRetryCount(prev => prev + 1); - // Re-run full extraction — don't reload the same bad URL + // Invalidate cache so loadTrailer gets a fresh URL, not the same bad one + if (trailer?.key) TrailerService.invalidateCache(trailer.key); loadTrailer(); return; } @@ -170,7 +171,7 @@ const TrailerModal: React.FC = memo(({ logger.error('TrailerModal', 'Video error after retries:', error); setError('Unable to play trailer. Please try again.'); setLoading(false); - }, [retryCount, loadTrailer]); + }, [retryCount, loadTrailer, trailer?.key]); const handleTrailerEnd = useCallback(() => { setIsPlaying(false); From 6e7a121be03e166b9983bf3fd920e35d1bad7b81 Mon Sep 17 00:00:00 2001 From: chrisk325 Date: Fri, 6 Mar 2026 13:43:04 +0530 Subject: [PATCH 5/5] minor fix to invalidate cache logic --- src/services/trailerService.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/services/trailerService.ts b/src/services/trailerService.ts index 0bb11cae..f2fa5492 100644 --- a/src/services/trailerService.ts +++ b/src/services/trailerService.ts @@ -14,8 +14,8 @@ interface CacheEntry { } export class TrailerService { - // Cache for 3 minutes — just enough to avoid re-extracting on quick re-renders - private static readonly CACHE_TTL_MS = 30 * 1000; + // Cache for 5 seconds — just enough to avoid re-extracting on quick re-renders + private static readonly CACHE_TTL_MS = 5 * 1000; private static urlCache = new Map(); // --------------------------------------------------------------------------- @@ -114,6 +114,11 @@ export class TrailerService { return { url, title, year }; } + static invalidateCache(videoId: string): void { + this.urlCache.delete(videoId); + logger.info('TrailerService', `Cache invalidated for videoId=${videoId}`); + } + static setUseLocalServer(_useLocal: boolean): void {} static getServerStatus(): { usingLocal: boolean; localUrl: string } {