From 1cadc2473f9640af8fb8481a15be45844df56173 Mon Sep 17 00:00:00 2001 From: chrisk325 Date: Fri, 20 Mar 2026 19:59:06 +0530 Subject: [PATCH] fix duplicate trakt entries while pausing and resuming content --- src/components/player/hooks/useWatchProgress.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/player/hooks/useWatchProgress.ts b/src/components/player/hooks/useWatchProgress.ts index 99a7b63b..a8ac8a17 100644 --- a/src/components/player/hooks/useWatchProgress.ts +++ b/src/components/player/hooks/useWatchProgress.ts @@ -210,6 +210,11 @@ export const useWatchProgress = ( wasPausedRef.current = paused; if (becamePaused) { void saveWatchProgress(); + } else { + // Became unpaused — open/re-open the Trakt scrobble session + if (durationRef.current > 0) { + void traktAutosyncRef.current.handlePlaybackStart(currentTimeRef.current, durationRef.current); + } } } @@ -238,7 +243,8 @@ export const useWatchProgress = ( setTimeout(() => { if (id && type && durationRef.current > 0) { saveWatchProgress(); - traktAutosync.handlePlaybackEnd(currentTimeRef.current, durationRef.current, 'unmount'); + // Use ref to avoid stale closure capturing an old traktAutosync instance + traktAutosyncRef.current.handlePlaybackEnd(currentTimeRef.current, durationRef.current, 'unmount'); } }, 0); };