mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
fix(studio): thumbnails of compositions with no code of their own load in under a second (#8316)
* fix(studio): thumbnails of compositions with no code of their own load in under a second Both thumbnail paths (the CLI's preview server and Studio's dev server) waited up to 5 s for a GSAP timeline before shooting a card. A composition with no script never registers one, so each of its cards took the full 5 s, and the route shoots one card at a time, so the third card came at about 16 s. The wait cannot simply go: a composition may register its timeline late, in a timer or a load handler, after the runtime is ready, and shooting it then shows the wrong moment. So the preview route now marks the page a thumbnail loads when nothing on it can register a timeline: no script but Studio's own (the runtime, GSAP core, an import map, the registry line), no inline event handler, frame, template or child composition loaded at run time, and no Studio motion. A marked page is shot once the runtime is ready. Every other page is held for its timeline exactly as before. The rule lives once, in studio-server, and both thumbnail paths wait on it. fails without the fix: "is skipped for a composition with no code of its own" and "holds for a composition whose script registers its timeline late" (packages/studio-server/src/routes/preview.thumbnailMark.test.ts), "thumbnailSeekReadyInBrowser" (packages/studio-server/src/helpers/screenshotClip.test.ts), "hasAuthoredCode" (packages/studio-server/src/helpers/authoredCode.test.ts), and "holds a thumbnail's shot on the thumbnail readiness rule" (packages/cli/src/server/studioServer.test.ts and packages/studio/vite.browser.test.ts). * test(studio-server): the thumbnail mark test builds its page from elements, not parsed text The test read the served page back through DOMParser and innerHTML to hand its metas to the readiness rule, which code scanning reports as DOM text reinterpreted as HTML. It now finds the served page's meta tags with the compiler's own tag scanner and creates each one as an element, so no text is parsed as markup. Also adds a row to the code check's table: a script inside an inline SVG counts as code. fails without the fix: "is skipped for a composition with no code of its own" (packages/studio-server/src/routes/preview.thumbnailMark.test.ts) still fails when the route writes no mark.
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
HistoryBusyError,
|
||||
HistoryClosedError,
|
||||
} from "@hyperframes/studio-server";
|
||||
import { thumbnailSeekReadyInBrowser } from "@hyperframes/studio-server/screenshot-clip";
|
||||
import { loadHyperframeRuntimeSource } from "@hyperframes/core";
|
||||
import { loadRuntimeSource } from "./runtimeSource.js";
|
||||
import { findFFmpeg, findFFprobe } from "../browser/ffmpeg.js";
|
||||
@@ -719,11 +720,14 @@ describe("Studio thumbnail capture", () => {
|
||||
afterEach(async () => {
|
||||
await server?.shutdown();
|
||||
});
|
||||
function fakePageBrowser(onEvaluate = () => {}) {
|
||||
function fakePageBrowser(
|
||||
onEvaluate = () => {},
|
||||
waitForFunction = async (_ready: () => boolean) => {},
|
||||
) {
|
||||
const screenshot = vi.fn(async () => Buffer.from("jpeg"));
|
||||
const evaluate = vi.fn(async () => onEvaluate());
|
||||
const page = new Proxy(
|
||||
{ screenshot, evaluate },
|
||||
{ screenshot, evaluate, waitForFunction },
|
||||
{
|
||||
get: (target, key) =>
|
||||
key === "then"
|
||||
@@ -751,6 +755,18 @@ describe("Studio thumbnail capture", () => {
|
||||
signal,
|
||||
});
|
||||
|
||||
it("holds a thumbnail's shot on the thumbnail readiness rule", async () => {
|
||||
const waits: unknown[] = [];
|
||||
const { screenshot } = fakePageBrowser(undefined, async (ready) => {
|
||||
expect(screenshot).not.toHaveBeenCalled();
|
||||
waits.push(ready);
|
||||
});
|
||||
const dir = tmpProject();
|
||||
server = createStudioServer({ projectDir: dir });
|
||||
await expect(server.adapter.generateThumbnail?.(opts(dir))).resolves.toBeInstanceOf(Buffer);
|
||||
expect(waits[0]).toBe(thumbnailSeekReadyInBrowser);
|
||||
});
|
||||
|
||||
it("stops a thumbnail whose request is aborted before its screenshot", async () => {
|
||||
let abortOnEvaluate: AbortController | undefined;
|
||||
const { screenshot } = fakePageBrowser(() => abortOnEvaluate?.abort());
|
||||
|
||||
@@ -97,8 +97,9 @@ import { resolveAutoProxy } from "../utils/projectConfig.js";
|
||||
import {
|
||||
clearElementScreenshotIsolation,
|
||||
getElementScreenshotClip,
|
||||
type ScreenshotClip,
|
||||
thumbnailSeekReadyInBrowser,
|
||||
} from "@hyperframes/studio-server/screenshot-clip";
|
||||
import type { ScreenshotClip } from "@hyperframes/studio-server/screenshot-clip";
|
||||
import type { RenderJob } from "@hyperframes/producer";
|
||||
import { isWithinProjectRoot } from "@hyperframes/parsers/asset-resolution";
|
||||
import { seekCompositionTimeline } from "../capture/captureCompositionFrame.js";
|
||||
@@ -890,15 +891,7 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
|
||||
requiresWebGpu && session.softwareWebGpu,
|
||||
);
|
||||
await page
|
||||
.waitForFunction(
|
||||
() => {
|
||||
const w = window as Window & {
|
||||
__timelines?: Record<string, unknown>;
|
||||
};
|
||||
return !!(w.__timelines && Object.keys(w.__timelines).length > 0);
|
||||
},
|
||||
{ timeout: 5000 },
|
||||
)
|
||||
.waitForFunction(thumbnailSeekReadyInBrowser, { timeout: 5000 })
|
||||
.catch(() => {});
|
||||
},
|
||||
async (page) => {
|
||||
|
||||
Reference in New Issue
Block a user