From 5d05e2690e53068cd56ed819a1f14a193306242c Mon Sep 17 00:00:00 2001 From: EtienneLescot Date: Tue, 17 Nov 2026 12:25:57 +0100 Subject: [PATCH 1/2] fix(preview): keep scrubs playing while a new source loads (cherry picked from commit 5583df78b8e1d52dc11b39f2815c7d1a3e2711c3) --- .../NewEditorShell.togglePlay.test.tsx | 6 +- src/components/ai-edition/NewEditorShell.tsx | 6 +- .../VirtualPreview.playback.test.tsx | 55 +++++++++++++++++++ src/components/ai-edition/VirtualPreview.tsx | 11 +++- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/src/components/ai-edition/NewEditorShell.togglePlay.test.tsx b/src/components/ai-edition/NewEditorShell.togglePlay.test.tsx index 56ff0fc793..f00c8aafce 100644 --- a/src/components/ai-edition/NewEditorShell.togglePlay.test.tsx +++ b/src/components/ai-edition/NewEditorShell.togglePlay.test.tsx @@ -223,7 +223,7 @@ describe("NewEditorShell togglePlay cross-asset replay", () => { it.each([ true, false, - ])("keeps playback=%s when a manual seek crosses into another asset", async (playing) => { + ])("lets the preview resolve implicit seek intent when the transport is %s", async (playing) => { useProjectStore.setState({ document: makeCrossAssetDocument(), projectId: "p1", @@ -240,6 +240,8 @@ describe("NewEditorShell togglePlay cross-asset replay", () => { fireEvent.keyDown(document.body, { key: "ArrowRight", code: "ArrowRight" }); }); expect(mocks.latestSeekTarget?.timeSec).toBeGreaterThan(5); - expect(mocks.latestSeekTarget?.preservePlayback).toBe(playing); + // A replacement video briefly reports paused before metadata. The shell + // must leave an implicit seek to the preview's current or queued intent. + expect(mocks.latestSeekTarget?.preservePlayback).toBeUndefined(); }); }); diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsx index 6525642187..0082553197 100644 --- a/src/components/ai-edition/NewEditorShell.tsx +++ b/src/components/ai-edition/NewEditorShell.tsx @@ -582,9 +582,9 @@ export function NewEditorShell() { timeSec, isSource: false, requestId: ++seekSeqRef.current, - // Timeline and transcript seeks omit the flag. Carry the transport's - // intent across a source swap, as a seek within the same video does. - preservePlayback: preservePlayback ?? useProjectStore.getState().playing, + // The preview owns queued playback while another source loads. Its new + // video is initially paused, so the store is not the scrub's intent. + preservePlayback, }); }, [setCurrentTime, canSeek], diff --git a/src/components/ai-edition/VirtualPreview.playback.test.tsx b/src/components/ai-edition/VirtualPreview.playback.test.tsx index 1d34b6e3b4..7615bcb79b 100644 --- a/src/components/ai-edition/VirtualPreview.playback.test.tsx +++ b/src/components/ai-edition/VirtualPreview.playback.test.tsx @@ -1163,6 +1163,61 @@ describe("VirtualPreview replay", () => { expect(reportedTimes(onTimeChange).at(-1)).toBe(14); }); + it.each([ + { initiallyPlaying: true, firstIntent: undefined, nextIntent: undefined, shouldPlay: true }, + { initiallyPlaying: true, firstIntent: true, nextIntent: undefined, shouldPlay: true }, + { initiallyPlaying: true, firstIntent: true, nextIntent: false, shouldPlay: false }, + { initiallyPlaying: false, firstIntent: undefined, nextIntent: undefined, shouldPlay: false }, + ])("keeps a source-switch scrub playing unless explicitly paused: $firstIntent → $nextIntent", ({ + initiallyPlaying, + firstIntent, + nextIntent, + shouldPlay, + }) => { + const sources: VideoSource[] = [ + { id: "a1", src: "file:///tmp/a1.mp4", label: "a1" }, + { id: "a2", src: "file:///tmp/a2.mp4", label: "a2" }, + ]; + const clips = [clip("clip_1", "a1", 0, 5, 0), clip("clip_2", "a2", 0, 5, 5)]; + let seekTarget: { + timeSec: number; + requestId: number; + preservePlayback?: boolean; + } | null = null; + const view = render( + , + ); + const firstElement = view.container.querySelector("video"); + if (!firstElement) throw new Error("no initial video"); + const firstVideo = driveVideo(firstElement); + act(() => fireEvent.loadedMetadata(firstElement)); + if (initiallyPlaying) firstVideo.play(); + firstVideo.seekTo(3); + + act(() => { + seekTarget = { timeSec: 6, requestId: 1, preservePlayback: firstIntent }; + view.rerender( + , + ); + }); + const nextElement = view.container.querySelector("video"); + if (!nextElement || nextElement === firstElement) throw new Error("source did not switch"); + const nextVideo = driveVideo(nextElement); + expect(nextElement.paused).toBe(true); + + // Pointerup or a later drag position arrives while the new decoder is + // still paused before metadata. It must retain the scrub's play intent. + act(() => { + seekTarget = { timeSec: 6.5, requestId: 2, preservePlayback: nextIntent }; + view.rerender( + , + ); + }); + act(() => fireEvent.loadedMetadata(nextElement)); + expect(nextVideo.currentTime).toBe(1.5); + expect(nextElement.paused).toBe(!shouldPlay); + }); + it("does not let stale loadState in tick closure block clip boundary checks or timeline end", () => { const sources: VideoSource[] = [ { id: "a1", src: "file:///tmp/a1.mp4", label: "a1" }, diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsx index eb79d6f04f..2082df940c 100644 --- a/src/components/ai-edition/VirtualPreview.tsx +++ b/src/components/ai-edition/VirtualPreview.tsx @@ -1523,7 +1523,7 @@ export function VirtualPreview({ }, []); const seekToVirtualTime = useCallback( - (nextVirtualTimeSec: number, preservePlayback = false, forceResume = false) => { + (nextVirtualTimeSec: number, preservePlayback?: boolean, forceResume = false) => { const position = locateVirtualPosition(clips, nextVirtualTimeSec); if (!position) { videoRef.current?.pause(); @@ -1553,7 +1553,14 @@ export function VirtualPreview({ // race against the rAF tick's own boundary check: the native `ended` // event fires first, stops playback outright, and the multi-clip // timeline never advances — the "stops at clip end" bug. - const shouldContinuePlayback = preservePlayback && (forceResume || !videoRef.current?.paused); + // A scrub can publish again before the replacement video's metadata + // arrives. That element starts paused; keep the queued intent instead of + // turning pointerup or the next drag position into a request to stop. + // An explicit false still cancels the queued resume. + const shouldContinuePlayback = + preservePlayback === undefined + ? (pendingSeekRef.current?.play ?? !videoRef.current?.paused) + : preservePlayback && (forceResume || !videoRef.current?.paused); if (isAssetSwitch) { if (!shouldContinuePlayback) { From a0ca7ae6eec3aead870022d3e30fa8505bde8366 Mon Sep 17 00:00:00 2001 From: EtienneLescot Date: Tue, 17 Nov 2026 12:39:36 +0100 Subject: [PATCH 2/2] fix(preview): wait for metadata before resuming queued seeks (cherry picked from commit 22b5daeeee319b64dabeccd67ed559f43393bc92) --- .../VirtualPreview.playback.test.tsx | 56 +++++++++++++++++-- src/components/ai-edition/VirtualPreview.tsx | 4 ++ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/components/ai-edition/VirtualPreview.playback.test.tsx b/src/components/ai-edition/VirtualPreview.playback.test.tsx index 7615bcb79b..405a89fb4d 100644 --- a/src/components/ai-edition/VirtualPreview.playback.test.tsx +++ b/src/components/ai-edition/VirtualPreview.playback.test.tsx @@ -1164,15 +1164,47 @@ describe("VirtualPreview replay", () => { }); it.each([ - { initiallyPlaying: true, firstIntent: undefined, nextIntent: undefined, shouldPlay: true }, - { initiallyPlaying: true, firstIntent: true, nextIntent: undefined, shouldPlay: true }, - { initiallyPlaying: true, firstIntent: true, nextIntent: false, shouldPlay: false }, - { initiallyPlaying: false, firstIntent: undefined, nextIntent: undefined, shouldPlay: false }, - ])("keeps a source-switch scrub playing unless explicitly paused: $firstIntent → $nextIntent", ({ + { + initiallyPlaying: true, + firstIntent: undefined, + nextIntent: undefined, + shouldPlay: true, + intermediateImplicitSeek: false, + }, + { + initiallyPlaying: true, + firstIntent: true, + nextIntent: undefined, + shouldPlay: true, + intermediateImplicitSeek: false, + }, + { + initiallyPlaying: true, + firstIntent: true, + nextIntent: false, + shouldPlay: false, + intermediateImplicitSeek: false, + }, + { + initiallyPlaying: false, + firstIntent: undefined, + nextIntent: undefined, + shouldPlay: false, + intermediateImplicitSeek: false, + }, + { + initiallyPlaying: true, + firstIntent: true, + nextIntent: false, + shouldPlay: false, + intermediateImplicitSeek: true, + }, + ])("keeps source-switch intent (playing $initiallyPlaying; intermediate $intermediateImplicitSeek; next $nextIntent)", ({ initiallyPlaying, firstIntent, nextIntent, shouldPlay, + intermediateImplicitSeek, }) => { const sources: VideoSource[] = [ { id: "a1", src: "file:///tmp/a1.mp4", label: "a1" }, @@ -1204,11 +1236,23 @@ describe("VirtualPreview replay", () => { if (!nextElement || nextElement === firstElement) throw new Error("source did not switch"); const nextVideo = driveVideo(nextElement); expect(nextElement.paused).toBe(true); + if (intermediateImplicitSeek) { + act(() => { + seekTarget = { timeSec: 6.25, requestId: 2 }; + view.rerender( + , + ); + }); + } // Pointerup or a later drag position arrives while the new decoder is // still paused before metadata. It must retain the scrub's play intent. act(() => { - seekTarget = { timeSec: 6.5, requestId: 2, preservePlayback: nextIntent }; + seekTarget = { + timeSec: 6.5, + requestId: intermediateImplicitSeek ? 3 : 2, + preservePlayback: nextIntent, + }; view.rerender( , ); diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsx index 2082df940c..d3ad133fcc 100644 --- a/src/components/ai-edition/VirtualPreview.tsx +++ b/src/components/ai-edition/VirtualPreview.tsx @@ -1590,6 +1590,10 @@ export function VirtualPreview({ sourceTimeSec: position.sourceTimeSec, play: shouldContinuePlayback, }; + updateVirtualTime(position.virtualTimeSec); + // Metadata owns the pending seek and resume. Calling play now would + // queue a browser autoplay that a later paused seek cannot cancel. + return; } updateVirtualTime(position.virtualTimeSec); applySourceTime(video, position.sourceTimeSec);