Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

test(preview): pin the "any healthy source clears the card" rule

EtienneLescot6b9dbbc51c23
diff --git a/src/components/ai-edition/Preview.test.tsx b/src/components/ai-edition/Preview.test.tsx
index 6a9ef9d6b..db84828b8 100644
--- a/src/components/ai-edition/Preview.test.tsx
+++ b/src/components/ai-edition/Preview.test.tsx
@@ -240,6 +240,25 @@ describe("Preview keeps the stage when the media fails", () => {
expect(errorCard()).not.toBeInTheDocument();
});
+ // …including when the healthy report comes from a DIFFERENT asset. Only one
+ // source is mounted at a time, so that report means the playhead has moved
+ // onto a clip that plays — and a "Preview stopped" card over a picture that
+ // is visibly fine is the #395 latch again, quieter. Scrubbing back onto the
+ // dead asset remounts it and brings the card back on its own.
+ it("drops the card when the playhead moves onto a healthy asset", () => {
+ renderPreview({
+ videoSources: [source("moved"), source("fresh")],
+ clips: [clip("clip_a", "moved", 0, 10), clip("clip_b", "fresh", 10, 20)],
+ });
+
+ click("fail-moved");
+ expect(errorCard()).toBeInTheDocument();
+
+ click("recover-fresh");
+ expect(errorCard()).not.toBeInTheDocument();
+ expect(canvas()).toBeInTheDocument();
+ });
+
it("bumps the retry token and clears the card when the user retries", () => {
renderPreview({ videoSources: [source("truncated")], clips: [] });
expect(canvas()).toHaveAttribute("data-retry-token", "0");
diff --git a/src/components/ai-edition/Preview.tsx b/src/components/ai-edition/Preview.tsx
index 2764f2c5c..aaf04f2db 100644
--- a/src/components/ai-edition/Preview.tsx
+++ b/src/components/ai-edition/Preview.tsx
@@ -147,6 +147,15 @@ export function Preview({
const handleVideoError = useCallback((assetId: string, detail: string) => {
setFailure({ assetId, detail });
}, []);
+ // The reported asset id is deliberately ignored. Exactly one source is mounted
+ // at a time (`videoSources[sourceIndex]` in VirtualPreview), and it is always
+ // the one the playhead needs — so ANY source reporting healthy means the stage
+ // is showing a real picture, whichever asset it belongs to. Matching the id
+ // against the failed one instead would keep "Preview stopped" pinned over a
+ // clip that is playing perfectly, until the user happened to scrub back to the
+ // dead one: a card outliving its failure, which is the latch of #395 again in
+ // a quieter form. Moving back onto the dead asset remounts it and earns a
+ // fresh retry cycle, so the card returns on its own if it should.
// Fires on every canplay, so on every seek: `setFailure(null)` against an
// already-null state is a React bail-out, and the healthy path costs nothing.
const handleVideoRecovered = useCallback(() => {