Skip to content
Merged
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
43 changes: 25 additions & 18 deletions packages/core/src/runtime/entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ async function evaluateRuntime(): Promise<void> {
await import("./entry");
}

function resetRuntimeGlobals(): void {
vi.useRealTimers();
window.__hfRuntimeTeardown?.();
document.head.innerHTML = "";
document.body.innerHTML = "";
window.__timelines = {};
delete window.__player;
delete window.__playerReady;
delete window.__renderReady;
delete window.__hfTimelinesBuilding;
const win = window as {
__hyperframeRuntimeBootstrapped?: boolean;
__hfFirstPassHidden?: boolean;
};
delete win.__hyperframeRuntimeBootstrapped;
delete win.__hfFirstPassHidden;
delete (document as { readyState?: unknown }).readyState;
}

// The first evaluation transforms the whole runtime graph. Paying it while the file loads keeps
// that one-time cost out of the first test's timeout; every test still evaluates a fresh copy.
await evaluateRuntime();
resetRuntimeGlobals();

const visibility = (...els: HTMLElement[]) => els.map((el) => getComputedStyle(el).visibility);
const imageSkipped = (...clips: HTMLElement[]) =>
clips.map((clip) => getComputedStyle(clip.querySelector("img")!).display === "none");
Expand All @@ -70,24 +94,7 @@ const neverDecodes = (clip: HTMLElement) => {
};

describe("runtime entry", () => {
afterEach(() => {
vi.useRealTimers();
window.__hfRuntimeTeardown?.();
document.head.innerHTML = "";
document.body.innerHTML = "";
window.__timelines = {};
delete window.__player;
delete window.__playerReady;
delete window.__renderReady;
delete window.__hfTimelinesBuilding;
const win = window as {
__hyperframeRuntimeBootstrapped?: boolean;
__hfFirstPassHidden?: boolean;
};
delete win.__hyperframeRuntimeBootstrapped;
delete win.__hfFirstPassHidden;
delete (document as { readyState?: unknown }).readyState;
});
afterEach(resetRuntimeGlobals);

it("paints no timed clip, from script evaluation until the first visibility pass decides it", async () => {
servePreview();
Expand Down
23 changes: 23 additions & 0 deletions packages/core/src/runtime/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3798,6 +3798,29 @@ describe("initSandboxRuntimeModular", () => {
expect(window.__renderReady).toBe(true);
});

it("a torn-down runtime's pending readiness check leaves the next document alone", () => {
vi.useFakeTimers();
try {
const root = document.createElement("div");
root.setAttribute("data-composition-id", "main");
root.setAttribute("data-root", "true");
root.setAttribute("data-start", "0");
document.body.appendChild(root);
window.__timelines = { main: createMockTimeline(10) };

initSandboxRuntimeModular();
window.__hfRuntimeTeardown?.();
// The next document is still batching its timelines when the old check fires.
delete window.__renderReady;
window.__hfTimelinesBuilding = true;
vi.runAllTimers();

expect(window.__renderReady).toBeUndefined();
} finally {
vi.useRealTimers();
}
});

it("sets __renderReady even without a GSAP timeline (CSS/WAAPI compositions)", () => {
const root = document.createElement("div");
root.setAttribute("data-composition-id", "main");
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/runtime/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4114,6 +4114,7 @@ export function initSandboxRuntimeModular(): void {
});

maybePublishRenderReady = () => {
if (state.tornDown) return;
if (!externalCompositionsReady) {
window.__renderReady = false;
return;
Expand Down
Loading