Skip to content

Commit 91845ef

Browse files
fix(studio): hold the player while the storyboard covers the film
A pause after the fact let J's reverse loop schedule its next frame, so the hidden film kept seeking. The stage now takes the player's own hold while the board is up (and only when no one else holds it), so J, Space and playback requests are refused before they start; Preview releases it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HebQXPiLcYKQfvPWB3Fgxy
1 parent 0952f44 commit 91845ef

3 files changed

Lines changed: 92 additions & 10 deletions

File tree

‎packages/studio/src/components/storyboard/PreviewStage.dom.test.tsx‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import type { StoryboardBoard } from "./useStoryboardBoard";
1010
const pauses = vi.fn();
1111
const player = create<{
1212
isPlaying: boolean;
13+
playLocked: boolean;
14+
setPlayLocked: (locked: boolean) => void;
1315
setIsPlaying: (playing: boolean) => void;
1416
requestPlayback: (playing: boolean) => void;
1517
requestSeek: (seconds: number) => void;
1618
}>((set) => ({
1719
isPlaying: false,
20+
playLocked: false,
21+
setPlayLocked: (playLocked) => set({ playLocked }),
1822
setIsPlaying: (isPlaying) => set({ isPlaying }),
1923
requestPlayback: (playing) => {
2024
if (!playing) pauses();
@@ -61,7 +65,7 @@ const boardShown = () => document.querySelector('[data-testid="board-view"]') !=
6165
beforeEach(() => {
6266
mounts = 0;
6367
board = noBoard;
64-
player.setState({ isPlaying: false });
68+
player.setState({ isPlaying: false, playLocked: false });
6569
const host = document.createElement("div");
6670
document.body.append(host);
6771
root = createRoot(host);
@@ -94,11 +98,17 @@ it("keeps the film mounted when the board goes and comes back", async () => {
9498
expect(mounts).toBe(1);
9599
});
96100

97-
it("pauses a play started while the board covers the film, as a shortcut would", async () => {
101+
it("holds the player while the board covers the film, and leaves another owner's hold alone", async () => {
102+
board = written;
103+
await render();
104+
expect(player.getState().playLocked).toBe(true);
105+
board = noBoard;
98106
await render();
107+
expect(player.getState().playLocked).toBe(false);
108+
player.setState({ playLocked: true });
99109
board = written;
100110
await render();
101-
pauses.mockClear();
102-
await act(async () => player.getState().setIsPlaying(true));
103-
expect(pauses).toHaveBeenCalledTimes(1);
111+
board = noBoard;
112+
await render();
113+
expect(player.getState().playLocked).toBe(true);
104114
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// @vitest-environment happy-dom
2+
import React, { act } from "react";
3+
import { createRoot, type Root } from "react-dom/client";
4+
import { afterEach, expect, it, vi } from "vitest";
5+
import {
6+
makeAdapterWindow,
7+
makeFakeIframe,
8+
renderTimelinePlayerHarness,
9+
resetPlayerStore,
10+
} from "../../player/hooks/timelinePlayerTestHarness";
11+
import { usePlayerStore } from "../../player/store/playerStore";
12+
import type { StoryboardBoard } from "./useStoryboardBoard";
13+
14+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
15+
16+
vi.mock("../../utils/studioTelemetry", () => ({ trackStudioEvent: vi.fn() }));
17+
vi.mock("./StoryboardBoardView", () => ({
18+
StoryboardBoardView: ({ onShowInPreview }: { onShowInPreview: (s: number | null) => void }) => (
19+
<button data-testid="back-to-film" onClick={() => onShowInPreview(null)} />
20+
),
21+
}));
22+
const board: StoryboardBoard = {
23+
path: "boards/storyboard.html",
24+
revision: 0,
25+
read: { state: "loading" },
26+
appeared: true,
27+
};
28+
vi.mock("./useStoryboardBoard", () => ({ useStoryboardBoard: () => board }));
29+
30+
const { PreviewStage } = await import("./PreviewStage");
31+
32+
let stage: Root | null = null;
33+
afterEach(() => {
34+
act(() => stage?.unmount());
35+
stage = null;
36+
document.body.innerHTML = "";
37+
resetPlayerStore();
38+
usePlayerStore.setState({ playLocked: false });
39+
vi.restoreAllMocks();
40+
});
41+
42+
const pressJ = () =>
43+
act(() => {
44+
window.dispatchEvent(new KeyboardEvent("keydown", { key: "j", code: "KeyJ" }));
45+
});
46+
47+
it("J under the board leaves the hidden film where it was, and works again back on Preview", () => {
48+
const frames: FrameRequestCallback[] = [];
49+
vi.spyOn(window, "requestAnimationFrame").mockImplementation((tick) => frames.push(tick));
50+
const { api, root } = renderTimelinePlayerHarness();
51+
const { adapter, win } = makeAdapterWindow();
52+
act(() => {
53+
api.iframeRef.current = makeFakeIframe(win);
54+
api.onIframeLoad();
55+
usePlayerStore.setState({ timelineReady: true });
56+
});
57+
adapter.seek(10);
58+
const host = document.createElement("div");
59+
document.body.append(host);
60+
stage = createRoot(host);
61+
act(() => stage!.render(<PreviewStage projectId="p1">{null}</PreviewStage>));
62+
63+
pressJ();
64+
for (const tick of frames.splice(0)) act(() => tick(1000));
65+
expect(adapter.getTime()).toBe(10);
66+
expect(frames).toHaveLength(0);
67+
68+
act(() => document.querySelector<HTMLButtonElement>('[data-testid="back-to-film"]')!.click());
69+
pressJ();
70+
expect(frames.length).toBeGreaterThan(0);
71+
act(() => root.unmount());
72+
});

‎packages/studio/src/components/storyboard/PreviewStage.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ export function PreviewStage({ projectId, children }: { projectId: string; child
3434
if (board.appeared) show("storyboard", "shown_on_write");
3535
}, [board.appeared, show]);
3636

37-
// The film is hidden under the board, so a play from anywhere (a shortcut, a stray request) is undone there.
37+
// The film is hidden under the board: the player's own hold refuses a play from anywhere (J, Space, a request)
38+
// before it starts. Another owner's hold is left as it is.
3839
useEffect(() => {
39-
if (tab !== "storyboard") return;
40-
return usePlayerStore.subscribe((state, prev) => {
41-
if (state.isPlaying && !prev.isPlaying) state.requestPlayback(false);
42-
});
40+
if (tab !== "storyboard" || usePlayerStore.getState().playLocked) return;
41+
usePlayerStore.getState().setPlayLocked(true);
42+
return () => usePlayerStore.getState().setPlayLocked(false);
4343
}, [tab]);
4444

4545
useEffect(() => {

0 commit comments

Comments
 (0)