Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/core/src/runtime/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,32 @@ describe("initSandboxRuntimeModular", () => {
window.cancelAnimationFrame = (() => {}) as typeof window.cancelAnimationFrame;
});

it("publishes progress from parent ticks while the iframe animation frame is suspended", () => {
document.body.innerHTML = '<div data-composition-id="main" data-duration="10"></div>';
window.__timelines = { main: createMockTimeline(10) };
initSandboxRuntimeModular();
const post = vi.spyOn(window.parent, "postMessage").mockImplementation(() => {});
let now = performance.now();
vi.spyOn(performance, "now").mockImplementation(() => now);
window.__player?.play();
post.mockClear();
now += 500;
window.dispatchEvent(
new MessageEvent("message", {
source: window,
data: { source: "hf-parent", type: "control", action: "tick" },
}),
);
expect(post).toHaveBeenCalledWith(
expect.objectContaining({
source: "hf-preview",
type: "state",
isPlaying: true,
frame: 15,
}),
"*",
);
});
it.each([
["2x", 5],
["0x2", 10],
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/runtime/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3988,7 +3988,10 @@ export function initSandboxRuntimeModular(): void {
runAdapters("pause");
syncMediaForCurrentState();
postState(true);
return;
}
// When iframe rAF is throttled, parent ticks also own position reporting.
postState(false);
},
onEnablePickMode: () => picker.enablePickMode(),
onDisablePickMode: () => picker.disablePickMode(),
Expand Down
Loading