diff --git a/packages/studio/src/hooks/useExternalFileChangeCoordinator.test.tsx b/packages/studio/src/hooks/useExternalFileChangeCoordinator.test.tsx
index ce42ce6b00..031b3c775f 100644
--- a/packages/studio/src/hooks/useExternalFileChangeCoordinator.test.tsx
+++ b/packages/studio/src/hooks/useExternalFileChangeCoordinator.test.tsx
@@ -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());
+ await act(async () => root.render());
+ 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
diff --git a/packages/studio/src/hooks/useExternalFileChangeCoordinator.ts b/packages/studio/src/hooks/useExternalFileChangeCoordinator.ts
index fc148c9a2b..997ac42e3d 100644
--- a/packages/studio/src/hooks/useExternalFileChangeCoordinator.ts
+++ b/packages/studio/src/hooks/useExternalFileChangeCoordinator.ts
@@ -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;
diff --git a/packages/studio/src/player/lib/thumbnailScheduler.ts b/packages/studio/src/player/lib/thumbnailScheduler.ts
index 5c2cbfbd5c..45a4e915fd 100644
--- a/packages/studio/src/player/lib/thumbnailScheduler.ts
+++ b/packages/studio/src/player/lib/thumbnailScheduler.ts
@@ -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();
});
}
diff --git a/packages/studio/src/player/lib/timelineViewportBudgets.test.ts b/packages/studio/src/player/lib/timelineViewportBudgets.test.ts
index 3c8a56496c..7e4d3cd22a 100644
--- a/packages/studio/src/player/lib/timelineViewportBudgets.test.ts
+++ b/packages/studio/src/player/lib/timelineViewportBudgets.test.ts
@@ -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,
diff --git a/packages/studio/src/player/lib/timelineViewportBudgets.ts b/packages/studio/src/player/lib/timelineViewportBudgets.ts
index 4e4c2e3e1c..9bc22bbd4e 100644
--- a/packages/studio/src/player/lib/timelineViewportBudgets.ts
+++ b/packages/studio/src/player/lib/timelineViewportBudgets.ts
@@ -72,7 +72,8 @@ export const TIMELINE_VIEWPORT_BUDGETS: Readonly = 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,