From 80da1bb3e2d054dedf069d7e3d2974430721de46 Mon Sep 17 00:00:00 2001 From: Admin Date: Wed, 4 Mar 2026 17:43:38 +0500 Subject: [PATCH] fix(audio): don't reset prefetch state for the chapter being consumed The stale-prefetch reset effect compared prefetchedFor against nextChapter only, so when landing on chapter N+1 (prefetchedFor=N+1, nextChapter=N+2) it would destroy the pre-fetched URL before startPlayback() could use it, breaking every auto-next transition after the first. Fix: also allow prefetchedFor === chapter (current page) so the URL survives long enough to be consumed, then only wipe truly foreign values. --- ui/src/lib/components/AudioPlayer.svelte | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ui/src/lib/components/AudioPlayer.svelte b/ui/src/lib/components/AudioPlayer.svelte index 976c39a..4066c2d 100644 --- a/ui/src/lib/components/AudioPlayer.svelte +++ b/ui/src/lib/components/AudioPlayer.svelte @@ -78,11 +78,16 @@ }); // Reset next-chapter prefetch state when this chapter changes (new page). - // We only reset if the prefetch is for a *different* chapter than nextChapter - // (i.e. stale data from a prior page). + // Only reset if the prefetch belongs to neither the current chapter + // (about to be consumed by startPlayback) nor the next chapter (still valid). + // Any other value means stale data from a previous page. $effect(() => { const prefetchedFor = audioStore.nextChapterPrefetched; - if (prefetchedFor !== null && prefetchedFor !== (nextChapter ?? null)) { + if ( + prefetchedFor !== null && + prefetchedFor !== chapter && + prefetchedFor !== (nextChapter ?? null) + ) { audioStore.resetNextPrefetch(); } });