fix(plex): Esc/Backspace actually cancels the auto-skip countdown

Cancelling only blanked skipProgress and flagged the marker — it never
stopped the running interval, so the next tick (~100ms later) re-set the
progress and the skip fired anyway. Hold the interval id in a ref and
clear it on cancel (and null it on completion/cleanup), so Esc/Backspace
truly stops the countdown; the Skip button stays for a manual skip.
This commit is contained in:
npeter83 2026-07-09 00:37:13 +02:00
parent 089eab76e4
commit dcdf48a811

View file

@ -796,6 +796,9 @@ export default function PlexPlayer({ itemId, onClose, queue }: Props) {
const [skipProgress, setSkipProgress] = useState<number | null>(null); const [skipProgress, setSkipProgress] = useState<number | null>(null);
skipProgressRef.current = skipProgress; skipProgressRef.current = skipProgress;
const cancelledMarkerRef = useRef<string | null>(null); const cancelledMarkerRef = useRef<string | null>(null);
// The running countdown interval, so cancelAutoSkip can actually STOP it — clearing skipProgress
// alone left the interval ticking, which re-set the progress ~100ms later and skipped anyway.
const skipTimerRef = useRef<number | null>(null);
const doSkip = useCallback( const doSkip = useCallback(
(m: PlexMarker) => { (m: PlexMarker) => {
setSkipProgress(null); setSkipProgress(null);
@ -807,6 +810,10 @@ export default function PlexPlayer({ itemId, onClose, queue }: Props) {
const cancelAutoSkip = useCallback(() => { const cancelAutoSkip = useCallback(() => {
const m = activeMarkerRef.current; const m = activeMarkerRef.current;
if (m) cancelledMarkerRef.current = `${m.type}-${m.start_s}`; // don't re-arm this same marker if (m) cancelledMarkerRef.current = `${m.type}-${m.start_s}`; // don't re-arm this same marker
if (skipTimerRef.current) {
window.clearInterval(skipTimerRef.current); // actually stop the countdown, not just blank it
skipTimerRef.current = null;
}
setSkipProgress(null); setSkipProgress(null);
}, []); }, []);
cancelAutoSkipRef.current = cancelAutoSkip; cancelAutoSkipRef.current = cancelAutoSkip;
@ -828,10 +835,15 @@ export default function PlexPlayer({ itemId, onClose, queue }: Props) {
setSkipProgress(p); setSkipProgress(p);
if (p >= 1) { if (p >= 1) {
window.clearInterval(iv); window.clearInterval(iv);
skipTimerRef.current = null;
doSkip(m); doSkip(m);
} }
}, 100); }, 100);
return () => window.clearInterval(iv); skipTimerRef.current = iv;
return () => {
window.clearInterval(iv);
skipTimerRef.current = null;
};
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [activeMarker?.type, activeMarker?.start_s, prefs.autoSkipIntro, prefs.autoSkipCredits, prefs.autoSkipDelay, doSkip]); }, [activeMarker?.type, activeMarker?.start_s, prefs.autoSkipIntro, prefs.autoSkipCredits, prefs.autoSkipDelay, doSkip]);