diff --git a/packages/studio/src/player/hooks/useShadowPreviewReload.ts b/packages/studio/src/player/hooks/useShadowPreviewReload.ts index 500c339eef..d893afc474 100644 --- a/packages/studio/src/player/hooks/useShadowPreviewReload.ts +++ b/packages/studio/src/player/hooks/useShadowPreviewReload.ts @@ -14,6 +14,7 @@ import { } from "./useTimelineSyncCallbacks"; import type { PlaybackAdapter } from "../lib/playbackTypes"; import { thumbnailScheduler } from "../lib/thumbnailScheduler"; +import { usePlayerStore } from "../store/playerStore"; // The single wait budget for a shadow: the player's 8s asset cap plus its 0.42s loader fade // leaves about 6.5s for the document load and runtime boot. Nothing shorter may fail the swap. @@ -191,6 +192,8 @@ export function useShadowPreviewReload({ shadowIframeRef.current = null; isRefreshingRef.current = false; pendingSeekRef.current = null; + // The new composition's preview isn't playable yet; its load step marks it ready again. + usePlayerStore.getState().setTimelineReady(false); setPreviewSlots(planShadowDiscard); thumbnailScheduler.setPreviewReloading(false); }, [stopPendingShadow, isRefreshingRef, pendingSeekRef]); diff --git a/packages/studio/src/player/hooks/useTimelinePlayer.play.test.ts b/packages/studio/src/player/hooks/useTimelinePlayer.play.test.ts index c11f4abe5c..830086a611 100644 --- a/packages/studio/src/player/hooks/useTimelinePlayer.play.test.ts +++ b/packages/studio/src/player/hooks/useTimelinePlayer.play.test.ts @@ -38,3 +38,23 @@ it("does not start playback before the timeline is ready, so iframe load cannot expect(usePlayerStore.getState().isPlaying).toBe(true); act(() => root.unmount()); }); + +it("does not start playback while a switched-to composition's preview is still loading", () => { + const { api, root } = renderTimelinePlayerHarness(); + act(() => { + api.iframeRef.current = makeFakeIframe(makeAdapterWindow().win); + api.onIframeLoad(); + usePlayerStore.setState({ timelineReady: true }); + }); + + // Drill into another composition: a fresh preview whose runtime is up but whose load step hasn't run. + const next = makeAdapterWindow(); + act(() => { + api.resetPreviewSlots(); + api.iframeRef.current = makeFakeIframe(next.win); + }); + act(() => api.play()); + expect(next.adapter.play).not.toHaveBeenCalled(); + expect(usePlayerStore.getState().isPlaying).toBe(false); + act(() => root.unmount()); +});