From 7f116f06571acbb60b74874c9ba5af5720c0f1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A6=D0=B2=D1=8B=D0=BB=D0=B5=D0=B2=20=D0=90=D0=BB=D0=B5?= =?UTF-8?q?=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20=D0=92=D0=B0=D0=B4=D0=B8?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2=D0=B8=D1=87?= Date: Wed, 29 Jul 2026 10:53:48 +0300 Subject: [PATCH] fix(player): clean up audio listeners + keep position on URL change - register named listeners with cleanup so a remount (StrictMode) can't leave duplicates double-dispatching - when the same track's URL changes (quality switch or token refresh), resume at the current position instead of restarting from 0 Co-Authored-By: Claude Opus 4.8 --- src/hooks/useAudioPlayer.ts | 59 ++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/src/hooks/useAudioPlayer.ts b/src/hooks/useAudioPlayer.ts index 128922c..c441926 100644 --- a/src/hooks/useAudioPlayer.ts +++ b/src/hooks/useAudioPlayer.ts @@ -31,38 +31,43 @@ export function useAudioPlayer() { // on demand; a cache miss transparently falls back to the original. const { data: settings } = useGetSettingsQuery(); const streamQuality = settings?.streamQuality; - const isSetup = useRef(false); - // `ended` is registered once below; read the latest loop flag through a ref - // so the listener doesn't need to be re-bound on every queue change. + // `ended` reads the latest loop flag through a ref so the listener doesn't + // need re-binding on every queue change. const loopRef = useRef(queue.loop); loopRef.current = queue.loop; + // The track id the current