mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
fix(studio): hold play on a composition switch until the new preview loads
Readiness was reset only when the project changed. Drilling into another composition kept the old ready flag while the new preview loaded, so Play or Space could start a play that its load step then undid.
This commit is contained in:
@@ -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]);
|
||||
|
||||
@@ -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());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user