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:
@@ -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;
|
||||
});
|
||||
}
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user