mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
* perf(studio): keep timeline bulk actions under a second, hand-move at most 3 clips Dragging or keyboard-moving a selection of 4 or more clips is refused with a toast pointing at the prompt box; 1 to 3 clips move as before. Root causes of the multi-second waits on large projects: - every selected clip fired its own source-existence probe; they now leave as one request per file - a timeline delete sent one request per clip, each re-parsing the file; it is now one request that parses once - each click on a clip from another file re-fetched GSAP data for every composition; covered files are kept and unchanged files answer 304 - any root index.html write re-captured every composition thumbnail; only a root head edit does now, since a scene page borrows nothing else from it Adds timeline-bulk-actions.mjs, a browser benchmark of select-all, move 3 and delete-all on a real project. * chore(studio): trim the bulk benchmark header to the comment limit * refactor(studio): tidy the bulk-action fixes after review Root head memo is keyed by the root file's content so every subscriber of one write gets one answer, and a thumbnail request can no longer overwrite it. The GSAP read reuses the shared content version as its ETag. * fix(studio): keep a head edit's thumbnail refresh when a later write replaces it File changes coalesce to the newest while a drain is in flight, so the affected-composition lists are merged instead of replaced. A failed GSAP read stays unloaded and is retried, and the GSAP read's ETag is salted with the parser version. * feat(studio): cap hand-resizing a multi-selection at 3 clips like moving Dragging a resize edge with 4 or more clips selected is refused with the same toast as a move; the rule is one constant and one helper shared by pointer move, pointer resize and keyboard pickup. * fix(studio): keep a head edit's thumbnail refresh through a replaced conflict A newer blocked change replaces the held one, so it now inherits the thumbnails the held one owed. * fix(studio): keep a held head edit's thumbnail refresh when a later write saves cleanly The clean-save path and the failed-cleanup path now merge the held blocked change's affected compositions, and the blocked-state merge runs inside the state update so two conflicts in one tick cannot lose the first. * chore(studio): keep useTimelineClipDrag under the 600-line cap * feat(studio): cap by the clips an edit would change, and cut the added comments The 3-clip rule counts the clips a move or trim would write to: a locked clip swept into a move stays put, and a trim some member cannot take edits only the grabbed clip. Comment share is back at or under the base in every changed file. * fix(studio): clear fallow audit and comment length on the multi-select cap * fix(studio): keep bench script comments under the block limit * fix(studio): keep the failed file's payload when another file's snapshot delete fails
145 lines
4.6 KiB
TypeScript
145 lines
4.6 KiB
TypeScript
// @vitest-environment happy-dom
|
|
|
|
import React, { act } from "react";
|
|
import { createRoot, type Root } from "react-dom/client";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { usePopulateKeyframeCacheForFile } from "./useGsapTweenCache";
|
|
import { usePlayerStore } from "../player/store/playerStore";
|
|
|
|
Reflect.set(globalThis, "IS_REACT_ACT_ENVIRONMENT", true);
|
|
|
|
function HookHost({ sourceFile = "index.html", version = 1 }) {
|
|
usePopulateKeyframeCacheForFile("demo", sourceFile, version);
|
|
return null;
|
|
}
|
|
|
|
let root: Root | null = null;
|
|
let container: HTMLElement | null = null;
|
|
|
|
beforeEach(() => {
|
|
usePlayerStore.setState({
|
|
timelineProjectId: "demo",
|
|
previewBooted: true,
|
|
elements: [
|
|
{
|
|
id: "lab",
|
|
tag: "div",
|
|
start: 0,
|
|
duration: 12,
|
|
track: 1,
|
|
compositionSrc: "compositions/keyframe-lab.html",
|
|
},
|
|
] as never,
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (root) {
|
|
act(() => root?.unmount());
|
|
root = null;
|
|
}
|
|
container?.remove();
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
describe("usePopulateKeyframeCacheForFile", () => {
|
|
it("loads every sub-composition file the timeline shows, not just the active one", async () => {
|
|
// Keyframe lanes must be populated when the project opens. Fetching only the
|
|
// active file left them empty until a clip from the sub-composition was
|
|
// selected (which is the only thing that switched `sourceFile`).
|
|
const urls: string[] = [];
|
|
const fetchMock = vi.fn((input: RequestInfo | URL) => {
|
|
urls.push(String(input));
|
|
return Promise.resolve({ ok: true, json: () => Promise.resolve({ animations: [] }) });
|
|
});
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
|
|
act(() => {
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
root = createRoot(container);
|
|
root.render(<HookHost />);
|
|
});
|
|
await act(async () => {
|
|
await Promise.resolve();
|
|
});
|
|
|
|
expect(urls.some((u) => u.endsWith("/index.html"))).toBe(true);
|
|
expect(urls.some((u) => u.includes("keyframe-lab.html"))).toBe(true);
|
|
});
|
|
|
|
it("keeps every covered file when the selection switches between them, and refetches all on new data", async () => {
|
|
// Every click on a clip from another file flips `sourceFile`; a flip must not
|
|
// re-read every composition file, or a multi-select pays files x clicks fetches.
|
|
const urls: string[] = [];
|
|
vi.stubGlobal(
|
|
"fetch",
|
|
vi.fn((input: RequestInfo | URL) => {
|
|
urls.push(String(input));
|
|
return Promise.resolve({ ok: true, json: () => Promise.resolve({ animations: [] }) });
|
|
}),
|
|
);
|
|
const render = async (props: { sourceFile: string; version: number }) => {
|
|
await act(async () => {
|
|
if (!root) {
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
root = createRoot(container);
|
|
}
|
|
root.render(<HookHost {...props} />);
|
|
});
|
|
await act(async () => {
|
|
await Promise.resolve();
|
|
});
|
|
};
|
|
|
|
await render({ sourceFile: "index.html", version: 1 });
|
|
const loaded = urls.length;
|
|
await render({ sourceFile: "compositions/keyframe-lab.html", version: 1 });
|
|
expect(urls.length).toBe(loaded);
|
|
await render({ sourceFile: "index.html", version: 1 });
|
|
expect(urls.length).toBe(loaded);
|
|
|
|
await render({ sourceFile: "index.html", version: 2 });
|
|
expect(urls.length).toBe(loaded * 2);
|
|
});
|
|
|
|
it("asks again for a covered file whose first read failed", async () => {
|
|
const urls: string[] = [];
|
|
vi.stubGlobal(
|
|
"fetch",
|
|
vi.fn((input: RequestInfo | URL) => {
|
|
const url = String(input);
|
|
urls.push(url);
|
|
const failed =
|
|
url.includes("keyframe-lab.html") && urls.filter((u) => u === url).length === 1;
|
|
return Promise.resolve({
|
|
ok: !failed,
|
|
json: () => Promise.resolve({ animations: [] }),
|
|
});
|
|
}),
|
|
);
|
|
const render = async (sourceFile: string) => {
|
|
await act(async () => {
|
|
if (!root) {
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
root = createRoot(container);
|
|
}
|
|
root.render(<HookHost sourceFile={sourceFile} />);
|
|
});
|
|
await act(async () => {
|
|
await Promise.resolve();
|
|
});
|
|
};
|
|
|
|
await render("index.html");
|
|
const labReads = () => urls.filter((u) => u.includes("keyframe-lab.html")).length;
|
|
expect(labReads()).toBe(1);
|
|
await render("compositions/keyframe-lab.html");
|
|
expect(labReads()).toBe(2);
|
|
await render("index.html");
|
|
expect(labReads()).toBe(2);
|
|
});
|
|
});
|