fix(player): keep playing the current video when it leaves the live feed queue

Auto-marking a video watched near its end invalidates the feed query; the
refetched/reordered queue can no longer contain the playing item, so
findIndex returned -1 and the active item fell back to queue[0] — silently
jumping playback to an unrelated video and defeating Loop "One" (and
auto-advance:off). Pin the last resolved video in a ref and keep playing it
when it drops out of the queue instead of snapping to queue[0].
This commit is contained in:
npeter83 2026-07-05 19:49:39 +02:00
parent 2ee4d563f6
commit 0fff5ad35d
3 changed files with 21 additions and 4 deletions

View file

@ -93,9 +93,18 @@ export default function PlayerModal({
// `video` in the queue (the feed passes its whole list + the clicked video, no index).
startIndex != null ? queue?.[startIndex]?.id ?? video.id : video.id
);
let index = queue ? queue.findIndex((v) => v.id === playingId) : 0;
if (index < 0) index = 0;
const active = queue && queue[index] ? queue[index] : video;
// Resolve the playing item from the LIVE queue so prev/next + the N/M counter track it. But
// the feed query reorders/refetches under us — e.g. auto-marking the current video watched near
// its end invalidates the feed — and the playing item can drop OUT of the loaded queue. When
// that happens we must KEEP PLAYING it, not snap back to queue[0] (which would silently jump to
// an unrelated video mid-playback, ignoring loop/auto-advance). So pin the last resolved video
// in a ref and fall back to it; neighbour stepping just treats it as sitting before queue[0].
const foundIndex = queue ? queue.findIndex((v) => v.id === playingId) : -1;
const inQueue = foundIndex >= 0;
const activeRef = useRef<Video>(video);
const active = inQueue ? queue![foundIndex] : activeRef.current;
activeRef.current = active;
const index = inQueue ? foundIndex : 0;
const hasQueue = !!queue && queue.length > 1;
// startAt only applies to the item we opened with; advanced items resume their own pos.
const resumeAt =