From 068bc6f78885c3b50d0b1072d5be37fe53bccfdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C4=B0pek?= Date: Tue, 24 Feb 2026 18:23:20 +0300 Subject: [PATCH] fix(player): stop YouTube iframe re-init loop --- .gitignore | 2 +- components/video-page-content.tsx | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c41959f..42b5474 100644 --- a/.gitignore +++ b/.gitignore @@ -45,5 +45,5 @@ next-env.d.ts # Progress (Internal Tracking) PROGRESS.md -OPTIMIZATION.md +OPTIMIZATIONS.md .kilocode \ No newline at end of file diff --git a/components/video-page-content.tsx b/components/video-page-content.tsx index 42fa914..07dc95b 100644 --- a/components/video-page-content.tsx +++ b/components/video-page-content.tsx @@ -313,6 +313,7 @@ export function VideoPageContent({ mode, videoId, projectId: propProjectId }: Vi // Watch progress state const [savedProgress, setSavedProgress] = useState(null); const [showResumePrompt, setShowResumePrompt] = useState(false); + const videoDurationRef = useRef(0); const progressSaveTimerRef = useRef | null>(null); const progressDebounceTimerRef = useRef | null>(null); const progressWriteInFlightRef = useRef(false); @@ -845,7 +846,7 @@ export function VideoPageContent({ mode, videoId, projectId: propProjectId }: Vi const progress = Math.max(0, input.progress); if (progress <= 0) return; - const duration = Math.max(0, input.duration ?? videoDuration ?? 0); + const duration = Math.max(0, input.duration ?? videoDurationRef.current ?? 0); const force = input.force ?? false; if (!force && Math.abs(progress - lastSavedProgressRef.current) < 2) { @@ -878,7 +879,7 @@ export function VideoPageContent({ mode, videoId, projectId: propProjectId }: Vi progressDebounceTimerRef.current = null; void flushScheduledWatchProgress(); }, 800); - }, [video?.isAuthenticated, activeVersionId, videoDuration, flushScheduledWatchProgress]); + }, [video?.isAuthenticated, activeVersionId, flushScheduledWatchProgress]); useEffect(() => { return () => { @@ -889,6 +890,10 @@ export function VideoPageContent({ mode, videoId, projectId: propProjectId }: Vi }; }, []); + useEffect(() => { + videoDurationRef.current = videoDuration; + }, [videoDuration]); + useEffect(() => { lastSavedProgressRef.current = 0; pendingProgressPayloadRef.current = null;