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:
@@ -70,9 +70,11 @@
|
||||
});
|
||||
|
||||
// Auto-start: if the layout navigated here via auto-next, kick off playback.
|
||||
// We match against the chapter prop so the outgoing chapter's AudioPlayer
|
||||
// (still mounted during the brief navigation window) never reacts to this.
|
||||
$effect(() => {
|
||||
if (audioStore.autoStartPending) {
|
||||
audioStore.autoStartPending = false;
|
||||
if (audioStore.autoStartChapter === chapter) {
|
||||
audioStore.autoStartChapter = null;
|
||||
startPlayback();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user