Open source CapCut alternative.
TypeScript
fix(site): guard preview-audio clears and contact-sheet retry deletes [rebuild]
David Le435d51fe2ebf
diff --git a/site/src/cut/lib/previewAudio.ts b/site/src/cut/lib/previewAudio.tsindex 89da65aa..3e347c4a 100644--- a/site/src/cut/lib/previewAudio.ts+++ b/site/src/cut/lib/previewAudio.ts@@ -30,12 +30,13 @@ export const usePreviewAudio = create<PreviewAudioState>((set, get) => ({}audio.src = url;audio.onended = () => set({ url: null });- audio.onerror = () => set({ url: null });+ // Only the load that still owns the state may clear it — a superseded load's+ // late error/rejection must not knock out the preview playing now.+ audio.onerror = () => {+ if (get().url === url) set({ url: null });+ };set({ url });void audio.play().catch(() => {- // A superseded play() rejects late ("interrupted by a new load- // request") — only the call still owning the state may clear it, or a- // stale rejection would knock out the preview playing now.if (get().url === url) set({ url: null });});},diff --git a/site/src/cut/server/frames.ts b/site/src/cut/server/frames.tsindex 36a323e7..07b3fc77 100644--- a/site/src/cut/server/frames.ts+++ b/site/src/cut/server/frames.ts@@ -276,7 +276,11 @@ export async function makeContactSheets(const deadline = Date.now() + WATCH_BUDGET_MS;let run = await runCapture(args(true), WATCH_BUDGET_MS);if (!run.ok && !run.timedOut && deadline - Date.now() > 5_000) {- for (const f of await readdir(tmp)) void unlink(path.join(tmp, f)).catch(() => {});+ // Await every stale-sheet delete before the retry writes new sheets to the+ // same paths, or a slow unlink can land after ffmpeg and wipe a fresh sheet.+ await Promise.all(+ (await readdir(tmp)).map((f) => unlink(path.join(tmp, f)).catch(() => {})),+ );run = await runCapture(args(false), deadline - Date.now());}