fix(audio): replace autoStartPending bool with autoStartChapter number

The boolean flag was set by onended before goto() resolved, causing the
still-mounted outgoing chapter's AudioPlayer $effect to fire and call
startPlayback() for the wrong (old) chapter — restarting it from scratch.

Replace with autoStartChapter (number | null): the AudioPlayer only acts
when its own chapter prop === autoStartChapter, so the outgoing component
never matches and the incoming one fires exactly once on mount.
This commit is contained in:
Admin
2026-03-04 18:08:12 +05:00
parent 80da1bb3e2
commit 0eee2eedf3
3 changed files with 17 additions and 8 deletions

View File

@@ -184,9 +184,11 @@
// we need.
const targetSlug = audioStore.slug;
const targetChapter = audioStore.nextChapter;
audioStore.autoStartPending = true;
// Store the target chapter number so only the newly-mounted AudioPlayer
// for that chapter reacts — not the outgoing chapter's component.
audioStore.autoStartChapter = targetChapter;
goto(`/books/${targetSlug}/chapters/${targetChapter}`).catch(() => {
audioStore.autoStartPending = false;
audioStore.autoStartChapter = null;
});
}
}}