mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
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.
17 lines
831 B
TypeScript
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);
|
|
}
|