Files
hyperframes/packages/studio/src/utils/previewPrefetch.test.ts
T
Miguel Ángel 302763b1a5 perf(studio): request the preview document at page load
Studio asked for the preview only once the player mounted, about 640 ms into a
first open. It now requests it the moment the page loads, and again when the
hash names another project, so the build or cache read overlaps Studio's boot.
2026-09-22 22:26:57 -04:00

23 lines
811 B
TypeScript

// @vitest-environment happy-dom
import { afterEach, describe, expect, it, vi } from "vitest";
import { prefetchPreviewForHash } from "./previewPrefetch";
describe("prefetchPreviewForHash", () => {
afterEach(() => vi.unstubAllGlobals());
it("requests the opening project's preview once, not on every hash update", () => {
const fetchStub = vi.fn(() => Promise.resolve(new Response("")));
vi.stubGlobal("fetch", fetchStub);
prefetchPreviewForHash("#project/demo");
prefetchPreviewForHash("#project/demo?t=2&tab=design");
prefetchPreviewForHash("#project/other");
prefetchPreviewForHash("#settings");
expect(fetchStub.mock.calls.map(([url]) => new URL(String(url)).pathname)).toEqual([
"/api/projects/demo/preview",
"/api/projects/other/preview",
]);
});
});