Skip to content

Open source CapCut alternative.

TypeScript

fix(site): a failed filmstrip ends its loading pulse [rebuild]

David Leccc15260ba91
diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsx
index 5ca46ccc..96b647c0 100644
--- a/site/src/cut/components/Timeline.tsx
+++ b/site/src/cut/components/Timeline.tsx
@@ -42,7 +42,7 @@ import { originalSettings, type ExportDoc } from "@/cut/lib/exportClient";
import { useExports } from "@/cut/lib/exportStore";
import { isDragActive, startDrag, subscribeDragActive } from "@/cut/lib/drag";
import { CLIP_GAP, startLaneMove, startLaneTrim, type LaneDrag, type LaneKind } from "@/cut/lib/laneTracks";
-import { downloadMedia, ensurePeaks, importImage, importStockMusic, importStockVideo, peekEdgeFrame, requestEdgeFrame, revealMedia } from "@/cut/lib/media";
+import { downloadMedia, ensurePeaks, importImage, importStockMusic, importStockVideo, peekEdgeFrame, requestEdgeFrame, revealMedia, stripFailedFor, subscribeStripStatus } from "@/cut/lib/media";
import { track0Clips, laneGapAt, sameLane, type LaneRef, clipLen, clipSpeed, getClipSpans, overlayLaneOrder, overlayLayers, projectDuration, resolveTransitions, rippleInsert, useEditor } from "@/cut/lib/store";
import type { VideoTrackPlacement } from "@/cut/lib/store";
import { playheadAt, setSkim, skimAt, subscribePlayhead, usePlayhead, useSkim } from "@/cut/lib/playhead";
@@ -3504,6 +3504,11 @@ function ClipView({
const startFrame = useEdgeFrame(asset, filmIn, `${clip.id}:in`);
const endFrame = useEdgeFrame(asset, filmOut, `${clip.id}:out`);
+ const stripFailed = useSyncExternalStore(
+ subscribeStripStatus,
+ () => stripFailedFor(asset.id),
+ () => false
+ );
const filmstrip = useMemo(
() =>
filmstripFrames(asset, filmIn, w, pps, speed, VIDEO_H - 4, 26, {
@@ -3565,7 +3570,7 @@ function ClipView({
});
}}
>
- <Filmstrip frames={filmstrip} grade={clip.grade} />
+ <Filmstrip frames={filmstrip} grade={clip.grade} failed={stripFailed} />
{selected && (
// A blue wash over the whole clip so a multi-selection reads at a
// glance, not just from the thin border.
@@ -3980,14 +3985,24 @@ function useEdgeFrame(asset: MediaAsset | undefined, time: number, slot: string)
function Filmstrip({
frames,
grade,
+ failed,
}: {
frames: { src: string; left: number; width: number }[];
grade?: ColorGrade;
+ /** The strip's last generation attempt failed: hold a still placeholder.
+ * An endless pulse reads as loading forever, and animating a clip-width
+ * element burns paint time for the life of the timeline. */
+ failed?: boolean;
}) {
const tint = gradeTint(grade);
// No thumbs yet — the media is still streaming into the browser store. A
// pulsing skeleton fills the box until the strip can draw real frames.
if (!frames.length) {
+ if (failed) {
+ return (
+ <div className="tl-filmstrip-failed pointer-events-none absolute inset-0 bg-accent" />
+ );
+ }
return (
<Skeleton className="tl-filmstrip-skeleton pointer-events-none absolute inset-0 rounded-none" />
);
diff --git a/site/src/cut/lib/media.ts b/site/src/cut/lib/media.ts
index dbcf6fe1..13c500d8 100644
--- a/site/src/cut/lib/media.ts
+++ b/site/src/cut/lib/media.ts
@@ -1403,6 +1403,30 @@ export async function composeSheets(
return sheets;
}
+// Filmstrip generation that failed, by asset id — session state, never doc
+// state. The clip box reads it to swap the loading pulse for a still
+// placeholder; each new enrich attempt (imports fire one, and every project
+// open sweeps all assets) clears the mark before trying again.
+const failedStrips = new Set<string>();
+const stripListeners = new Set<() => void>();
+
+export function subscribeStripStatus(fn: () => void) {
+ stripListeners.add(fn);
+ return () => {
+ stripListeners.delete(fn);
+ };
+}
+
+/** Whether the last filmstrip attempt for this asset failed. */
+export const stripFailedFor = (assetId: string) => failedStrips.has(assetId);
+
+function setStripFailed(assetId: string, failed: boolean) {
+ if (failed === failedStrips.has(assetId)) return;
+ if (failed) failedStrips.add(assetId);
+ else failedStrips.delete(assetId);
+ for (const fn of stripListeners) fn();
+}
+
/** Generate filmstrip thumbnails / waveform peaks and merge them into the
* store. Safe to call repeatedly; skips assets that are already enriched.
* `src` overrides where the frames are read from — an import still uploading
@@ -1415,12 +1439,16 @@ export async function enrichAsset(asset: MediaAsset, src = asset.url) {
useEditor.getState().updateAsset(asset.id, { thumbs: [src], thumbStep: IMAGE_CLIP_SECONDS });
}
} else if (asset.type === "video" && !asset.thumbs?.length) {
+ setStripFailed(asset.id, false);
const key = stripCacheKey(useEditor.getState().projectId, asset.fileName);
const cached = await readCachedStrip(key, asset.duration);
if (cached) {
useEditor.getState().updateAsset(asset.id, { thumbs: cached.thumbs, thumbStep: cached.thumbStep });
} else {
const { thumbs, thumbStep } = await makeThumbs(src, asset.duration);
+ // An empty strip is a failure, not a result: persisting it would
+ // leave the asset looking permanently mid-load.
+ if (!thumbs.length) throw new UnreadableMediaError("No frames could be read for the filmstrip.");
useEditor.getState().updateAsset(asset.id, { thumbs, thumbStep });
writeCachedStrip(key, { thumbs, thumbStep, duration: asset.duration, at: Date.now() });
}
@@ -1428,8 +1456,17 @@ export async function enrichAsset(asset: MediaAsset, src = asset.url) {
const peaks = await makePeaks(src);
useEditor.getState().updateAsset(asset.id, { peaks });
}
- } catch {
+ } catch (err) {
// Thumbnails and waveforms are decorative; editing works without them.
+ // The failure still gets recorded — clips stop their loading pulse — and
+ // logged at error level, which carries it into PostHog error tracking
+ // (console.error autocapture) with the file's shape beside the cause.
+ if (asset.type === "video") setStripFailed(asset.id, true);
+ console.error(
+ `[cut] enrich failed for ${asset.fileName}`,
+ { type: asset.type, durationSec: Math.round(asset.duration) },
+ err
+ );
}
}
@@ -1441,8 +1478,10 @@ export async function ensurePeaks(asset: MediaAsset) {
const peaks = await makePeaks(asset.url);
useEditor.getState().updateAsset(asset.id, { peaks });
}
- } catch {
- // Waveforms are decorative; editing works without them.
+ } catch (err) {
+ // Waveforms are decorative; editing works without them. Error level
+ // carries the failure into PostHog error tracking.
+ console.error(`[cut] peaks failed for ${asset.fileName}`, err);
}
}