Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

fix(ui): toast the first failed autosave; index rows in the draw loop

Jareer97384f8678d7
diff --git a/desktop/src/components/TimelinePanel.tsx b/desktop/src/components/TimelinePanel.tsx
index f9f143e3..9d8b2dbc 100644
--- a/desktop/src/components/TimelinePanel.tsx
+++ b/desktop/src/components/TimelinePanel.tsx
@@ -390,8 +390,12 @@ export function TimelinePanel({
context.rect(0, RULER_HEIGHT, width, Math.max(0, height - RULER_HEIGHT));
context.clip();
+ // Row index per track id, once per repaint - the loop below runs per
+ // clip per frame during playback, and a caption run puts hundreds of
+ // clips on the timeline.
+ const rowByTrack = new Map(state.rows.map((track, index) => [track.id, index]));
for (const clip of state.timeline.clips) {
- const rowIndex = state.rows.findIndex((track) => track.id === clip.trackId);
+ const rowIndex = rowByTrack.get(clip.trackId) ?? -1;
if (rowIndex < 0) continue;
const x = toX(clip.start);
diff --git a/desktop/src/hooks/useEngineSession.ts b/desktop/src/hooks/useEngineSession.ts
index 51d3da3e..d4227ed6 100644
--- a/desktop/src/hooks/useEngineSession.ts
+++ b/desktop/src/hooks/useEngineSession.ts
@@ -204,16 +204,31 @@ export function useEngineSession({
// Autosave, debounced. The engine writes the document; the UI only says
// when, and carries the output frame the preview footer can edit.
+ //
+ // A failure toasts once per losing streak - the first failed autosave is
+ // news the user must not miss (their edits are not reaching disk), but a
+ // full disk would otherwise toast every keystroke and a half. The streak
+ // resets on the next success so a recurrence speaks up again.
+ const autosaveFailing = useRef(false);
useEffect(() => {
if (!loaded) return;
const timer = window.setTimeout(() => {
setSaveState("saving");
editorSave(frameRef.current)
- .then(() => setSaveState("saved"))
- .catch(() => setSaveState("failed"));
+ .then(() => {
+ setSaveState("saved");
+ autosaveFailing.current = false;
+ })
+ .catch((cause: unknown) => {
+ setSaveState("failed");
+ if (!autosaveFailing.current) {
+ autosaveFailing.current = true;
+ onSaved(false, String(cause));
+ }
+ });
}, 1500);
return () => clearTimeout(timer);
- }, [view, frame, loaded]);
+ }, [view, frame, loaded, onSaved]);
const saveAndNotify = useCallback(() => {
setSaveState("saving");