mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
fix(studio): an edit no longer reopens the live-updates stream, and thumbnails ask one at a time
This commit is contained in:
@@ -83,6 +83,25 @@ describe("external file change coordinator", () => {
|
||||
expect(captured.handle?.blocked).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps one file-change subscription across re-renders and delivers to the latest callbacks", async () => {
|
||||
const on = vi.fn((_event: string, next: HotHandler) => void (handler = next));
|
||||
vi.stubGlobal("__HF_STUDIO_HOT_TEST_ADAPTER__", { on, off: vi.fn() });
|
||||
const { options } = await mountCoordinator();
|
||||
on.mockClear();
|
||||
const root = createRoot(document.createElement("div"));
|
||||
roots.push(root);
|
||||
function Probe({ onAccepted }: { onAccepted: () => void }) {
|
||||
useExternalFileChangeCoordinator({ ...options, onAcceptedPersistedFileChange: onAccepted });
|
||||
return null;
|
||||
}
|
||||
const latest = vi.fn();
|
||||
await act(async () => root.render(<Probe onAccepted={vi.fn()} />));
|
||||
await act(async () => root.render(<Probe onAccepted={latest} />));
|
||||
await act(async () => handler?.({ path: "index.html", content: "external", version: "v2" }));
|
||||
expect(on).toHaveBeenCalledOnce();
|
||||
expect(latest).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
// The file tree (useFileTree) is only ever refreshed from Studio's own file
|
||||
// operations (create/delete/rename/upload) — never on an external change.
|
||||
// Without this call, an agent removing or replacing a composition updates
|
||||
|
||||
@@ -425,9 +425,12 @@ export function useExternalFileChangeCoordinator({
|
||||
[projectId, pendingTimelineEditPathRef, startDrainLoop, onAcceptedPersistedFileChange],
|
||||
);
|
||||
|
||||
const processChangeRef = useRef(processChange);
|
||||
processChangeRef.current = processChange;
|
||||
// Subscribed once per mount: each resubscribe opened a new /api/events stream, which took a socket per edit.
|
||||
useEffect(() => {
|
||||
// One decoder for all three transports; the rungs only choose the channel.
|
||||
const handler = (delivery?: unknown) => processChange(decodeFileChange(delivery));
|
||||
const handler = (delivery?: unknown) => processChangeRef.current(decodeFileChange(delivery));
|
||||
const adapter = testHotAdapter();
|
||||
if (adapter) {
|
||||
adapter.on("hf:file-change", handler);
|
||||
@@ -438,7 +441,7 @@ export function useExternalFileChangeCoordinator({
|
||||
return () => import.meta.hot?.off?.("hf:file-change", handler);
|
||||
}
|
||||
return sseFileChangeChannel(handler);
|
||||
}, [processChange]);
|
||||
}, []);
|
||||
|
||||
const retry = useCallback(async () => {
|
||||
const current = blockedRef.current;
|
||||
|
||||
@@ -292,6 +292,16 @@ export class ThumbnailScheduler {
|
||||
entry.controller = controller;
|
||||
this.activeByBucket[bucket]++;
|
||||
this.activeByKind[entry.request.kind]++;
|
||||
let slotFree = false;
|
||||
// An aborted load gives its slot back at once: with one composition slot, a stale render must not hold it.
|
||||
const freeSlot = () => {
|
||||
if (slotFree) return;
|
||||
slotFree = true;
|
||||
this.activeByBucket[bucket]--;
|
||||
this.activeByKind[entry.request.kind]--;
|
||||
this.pump();
|
||||
};
|
||||
controller.signal.addEventListener("abort", freeSlot, { once: true });
|
||||
this.notify(entry);
|
||||
|
||||
const pending = this.loadWithTimeout(entry, controller);
|
||||
@@ -313,8 +323,7 @@ export class ThumbnailScheduler {
|
||||
})
|
||||
.finally(() => {
|
||||
if (entry.controller === controller) entry.controller = null;
|
||||
this.activeByBucket[bucket]--;
|
||||
this.activeByKind[entry.request.kind]--;
|
||||
freeSlot();
|
||||
this.pump();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ describe("timeline viewport budgets", () => {
|
||||
maxMountedTimelineDescendants: 5_000,
|
||||
thumbnailCacheBytes: 64 * 1024 * 1024,
|
||||
waveformCacheBytes: 16 * 1024 * 1024,
|
||||
concurrentCompositionFetches: 1,
|
||||
interactionP95Ms: 50,
|
||||
constrainedInteractionP95Ms: 75,
|
||||
constrainedFrameIntervalP95Ms: 75,
|
||||
|
||||
@@ -72,7 +72,8 @@ export const TIMELINE_VIEWPORT_BUDGETS: Readonly<TimelineViewportBudgets> = Obje
|
||||
richPreviewFrameCount: MAX_VISIBLE_THUMBNAIL_FRAMES,
|
||||
concurrentVideoDecodes: 2,
|
||||
concurrentMetadataJobs: 4,
|
||||
concurrentCompositionFetches: 2,
|
||||
// studio-server renders one thumbnail at a time; a second fetch only held a browser socket in its queue.
|
||||
concurrentCompositionFetches: 1,
|
||||
concurrentServerPages: 1,
|
||||
thumbnailLoadTimeoutMs: 30_000,
|
||||
thumbnailCacheBytes: 64 * MEBIBYTE,
|
||||
|
||||
Reference in New Issue
Block a user