Files
hyperframes/packages/studio/src/utils/previewPrefetch.ts
T
Miguel Ángel 38b2fa13c8 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-23 21:15:13 -04:00

17 lines
831 B
TypeScript

import { applyPreviewVariablesToUrl } from "../hooks/previewVariablesStore";
import { buildProjectApiPath, parseProjectIdFromHash } from "./projectRouting";
let prefetched: string | null = null;
/** Asks the server for the preview document of the project in the URL while Studio boots, so
* the build runs in parallel with the app instead of after the player mounts. */
export function prefetchPreviewForHash(hash: string): void {
const projectId = parseProjectIdFromHash(hash);
if (!projectId || projectId === prefetched) return;
prefetched = projectId;
const url = new URL(buildProjectApiPath(projectId, "/preview"), window.location.origin);
applyPreviewVariablesToUrl(url);
// ponytail: the response is dropped; the server keeps the built document for the player's request.
fetch(url).catch(() => undefined);
}