Skip to content

Commit 6b5ea82

Browse files
committed
feat(studio): timeline clip thumbnails off by default with a toolbar toggle
Background thumbnail generation (per-clip composition/video frame capture) lags timeline scrubbing on long videos (#2428). Adds a persisted thumbnailsEnabled setting, default OFF, so the timeline is snappy out of the box; a toggle next to Fit in the zoom toolbar turns thumbnails on. When off, clips render as plain bars (audio still shows its waveform).
1 parent 4c09679 commit 6b5ea82

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎packages/studio/src/components/TimelineToolbar.tsx‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useRef } from "react";
2-
import { Magnet, MagnifyingGlassMinus, MagnifyingGlassPlus } from "@phosphor-icons/react";
2+
import { Image, Magnet, MagnifyingGlassMinus, MagnifyingGlassPlus } from "@phosphor-icons/react";
33
import {
44
useEnableKeyframes,
55
isPlayheadWithinTween,
@@ -80,6 +80,8 @@ export function TimelineToolbar({ domEditSession, onSplitElement }: TimelineTool
8080
const setTimelineSnapEnabled = usePlayerStore((s) => s.setTimelineSnapEnabled);
8181
const autoKeyframeEnabled = usePlayerStore((s) => s.autoKeyframeEnabled);
8282
const setAutoKeyframeEnabled = usePlayerStore((s) => s.setAutoKeyframeEnabled);
83+
const thumbnailsEnabled = usePlayerStore((s) => s.thumbnailsEnabled);
84+
const setThumbnailsEnabled = usePlayerStore((s) => s.setThumbnailsEnabled);
8385
// Subscribe so the add-beat button reacts to playhead movement and analysis load.
8486
const currentTime = usePlayerStore((s) => s.currentTime);
8587
const beatAnalysisReady = usePlayerStore((s) => s.beatAnalysis !== null);
@@ -357,6 +359,21 @@ export function TimelineToolbar({ domEditSession, onSplitElement }: TimelineTool
357359
})()}
358360
</div>
359361
<div className="flex items-center gap-0.5">
362+
<Tooltip label={thumbnailsEnabled ? "Hide clip thumbnails" : "Show clip thumbnails"}>
363+
<button
364+
type="button"
365+
aria-label={thumbnailsEnabled ? "Hide clip thumbnails" : "Show clip thumbnails"}
366+
aria-pressed={thumbnailsEnabled}
367+
onClick={() => setThumbnailsEnabled(!thumbnailsEnabled)}
368+
className={`h-7 px-2 rounded-md text-[11px] font-medium transition-colors ${
369+
thumbnailsEnabled
370+
? "bg-studio-accent/10 text-studio-accent"
371+
: "text-neutral-400 hover:bg-white/[0.06] hover:text-neutral-200"
372+
}`}
373+
>
374+
<Image size={16} aria-hidden="true" />
375+
</button>
376+
</Tooltip>
360377
<Tooltip label="Fit timeline to width">
361378
<button
362379
type="button"

‎packages/studio/src/hooks/useRenderClipContent.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { TimelineElement } from "../player";
55
import { AudioWaveform } from "../player/components/AudioWaveform";
66
import { ImageThumbnail } from "../player/components/ImageThumbnail";
77
import { encodePreviewPath, resolveMediaPreviewUrl } from "../player/components/thumbnailUtils";
8+
import { usePlayerStore } from "../player/store/playerStore";
89

910
export function normalizeCompositionSrc(
1011
compSrc: string,
@@ -87,13 +88,22 @@ export function useRenderClipContent({
8788
activePreviewUrl,
8889
effectiveTimelineDuration,
8990
}: UseRenderClipContentOptions) {
91+
// Self-sourced (not threaded via App) so the toggle gates generation without
92+
// App.tsx plumbing. Off by default -> plain clip bars, snappy timeline (#2428).
93+
const thumbnailsEnabled = usePlayerStore((s) => s.thumbnailsEnabled);
9094
return useCallback(
9195
// Pre-existing clip-content dispatcher; reduced by extracting renderAudioClip.
9296
// fallow-ignore-next-line complexity
9397
(el: TimelineElement, style: { clip: string; label: string }): ReactNode => {
9498
const pid = projectIdRef.current;
9599
if (!pid) return null;
96100

101+
// Thumbnail generation disabled (perf) -> plain clip bars. Audio still shows
102+
// its waveform (cheap, not a frame thumbnail). Toggle: timeline toolbar.
103+
if (!thumbnailsEnabled) {
104+
return el.tag === "audio" ? renderAudioClip(el, pid, style.label) : null;
105+
}
106+
97107
let compSrc = el.compositionSrc;
98108
if (compSrc) {
99109
compSrc = normalizeCompositionSrc(compSrc, pid, window.location.origin);
@@ -182,6 +192,6 @@ export function useRenderClipContent({
182192

183193
return null;
184194
},
185-
[projectIdRef, compIdToSrc, activePreviewUrl, effectiveTimelineDuration],
195+
[projectIdRef, compIdToSrc, activePreviewUrl, effectiveTimelineDuration, thumbnailsEnabled],
186196
);
187197
}

‎packages/studio/src/player/store/playerStore.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ interface PlayerState extends KeyframeSlice {
109109
loopEnabled: boolean;
110110
/** Timeline zoom: 'fit' auto-scales to viewport, 'manual' uses manualZoomPercent */
111111
zoomMode: ZoomMode;
112+
thumbnailsEnabled: boolean;
112113
/** Timeline zoom percent relative to the fit width when in manual mode */
113114
manualZoomPercent: number;
114115
/**
@@ -196,6 +197,7 @@ interface PlayerState extends KeyframeSlice {
196197
>,
197198
) => void;
198199
setZoomMode: (mode: ZoomMode) => void;
200+
setThumbnailsEnabled: (enabled: boolean) => void;
199201
setManualZoomPercent: (percent: number) => void;
200202
bumpZEditVersion: () => void;
201203
setInPoint: (time: number | null) => void;
@@ -294,6 +296,7 @@ export const usePlayerStore = create<PlayerState>((set, get) => ({
294296
audioMuted: readStudioUiPreferences().audioMuted ?? false,
295297
loopEnabled: false,
296298
zoomMode: "fit",
299+
thumbnailsEnabled: readStudioUiPreferences().thumbnailsEnabled ?? false,
297300
manualZoomPercent: 100,
298301
zEditVersion: 0,
299302
timelinePps: 100,
@@ -409,6 +412,10 @@ export const usePlayerStore = create<PlayerState>((set, get) => ({
409412
writeStudioUiPreferences({ audioMuted: muted });
410413
set({ audioMuted: muted });
411414
},
415+
setThumbnailsEnabled: (enabled) => {
416+
writeStudioUiPreferences({ thumbnailsEnabled: enabled });
417+
set({ thumbnailsEnabled: enabled });
418+
},
412419
setLoopEnabled: (enabled) => set({ loopEnabled: enabled }),
413420
setZoomMode: (mode) => set({ zoomMode: mode }),
414421
clearSelectedElementIds: () => set({ selectedElementIds: new Set() }),

‎packages/studio/src/utils/studioUiPreferences.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface StudioUiPreferences {
1010
timelineHeight?: number;
1111
playbackRate?: number;
1212
audioMuted?: boolean;
13+
thumbnailsEnabled?: boolean;
1314
previewZoom?: StoredPreviewZoomState;
1415
recentBlocks?: string[];
1516
snapEnabled?: boolean;
@@ -70,6 +71,9 @@ function readStorage(storage: Storage | null): StudioUiPreferences {
7071
if (typeof parsed.audioMuted === "boolean") {
7172
preferences.audioMuted = parsed.audioMuted;
7273
}
74+
if (typeof parsed.thumbnailsEnabled === "boolean") {
75+
preferences.thumbnailsEnabled = parsed.thumbnailsEnabled;
76+
}
7377
if (isRecord(parsed.previewZoom)) {
7478
const { zoomPercent, panX, panY } = parsed.previewZoom;
7579
if (

0 commit comments

Comments
 (0)