🎥 Make videos programmatically with React
`@remotion/studio`: Reduce timeline zoom rendering work
JonnyBurgera9c3159b760b
diff --git a/packages/studio/src/components/Timeline/TimelinePinchZoom.tsx b/packages/studio/src/components/Timeline/TimelinePinchZoom.tsxindex c7aaa619b2..c6fed852d5 100644--- a/packages/studio/src/components/Timeline/TimelinePinchZoom.tsx+++ b/packages/studio/src/components/Timeline/TimelinePinchZoom.tsx@@ -23,7 +23,9 @@ type WebKitGestureEvent = UIEvent & {export const TimelinePinchZoom: FC = () => {const isVideoComposition = useIsVideoComposition();const videoConfig = Internals.useUnsafeVideoConfig();- const {getZoom, setZoom} = useContext(TimelineZoomImperativeContext);+ const {getZoom, setZoom, beginZoom, endZoom} = useContext(+ TimelineZoomImperativeContext,+ );const {editorZoomGestures} = useContext(EditorZoomGesturesContext);const getCurrentTimelineZoom = useCallback(@@ -115,6 +117,10 @@ export const TimelinePinchZoom: FC = () => {}const endWebKitPinch = () => {+ if (pinchBaseZoomRef.current !== null) {+ endZoom();+ }+pinchBaseZoomRef.current = null;suppressWheelFromWebKitPinchRef.current = false;};@@ -138,6 +144,7 @@ export const TimelinePinchZoom: FC = () => {suppressWheelFromWebKitPinchRef.current = true;pinchBaseZoomRef.current = getCurrentTimelineZoom(videoConfig.id);+ beginZoom();};const onGestureChange = (event: Event) => {@@ -180,6 +187,7 @@ export const TimelinePinchZoom: FC = () => {el.addEventListener('gesturecancel', onGestureEnd);return () => {+ endWebKitPinch();el.removeEventListener('gesturestart', onGestureStart);el.removeEventListener('gesturechange', onGestureChange);el.removeEventListener('gestureend', onGestureEnd);@@ -192,6 +200,8 @@ export const TimelinePinchZoom: FC = () => {videoConfig,getCurrentTimelineZoom,setZoom,+ beginZoom,+ endZoom,]);useEffect(() => {@@ -202,6 +212,10 @@ export const TimelinePinchZoom: FC = () => {const onTouchStart = (event: TouchEvent) => {if (event.touches.length !== 2) {+ if (touchPinchRef.current !== null) {+ endZoom();+ }+touchPinchRef.current = null;return;}@@ -227,6 +241,7 @@ export const TimelinePinchZoom: FC = () => {initialDistance,initialZoom: getCurrentTimelineZoom(videoConfig.id),};+ beginZoom();};const onTouchMove = (event: TouchEvent) => {@@ -265,6 +280,10 @@ export const TimelinePinchZoom: FC = () => {const onTouchEnd = (event: TouchEvent) => {if (event.touches.length < 2) {+ if (touchPinchRef.current !== null) {+ endZoom();+ }+touchPinchRef.current = null;}};@@ -275,6 +294,11 @@ export const TimelinePinchZoom: FC = () => {el.addEventListener('touchcancel', onTouchEnd);return () => {+ if (touchPinchRef.current !== null) {+ touchPinchRef.current = null;+ endZoom();+ }+el.removeEventListener('touchstart', onTouchStart);el.removeEventListener('touchmove', onTouchMove);el.removeEventListener('touchend', onTouchEnd);@@ -286,6 +310,8 @@ export const TimelinePinchZoom: FC = () => {videoConfig,getCurrentTimelineZoom,setZoom,+ beginZoom,+ endZoom,]);return null;diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsxindex daf0368f8f..b3ab7295d4 100644--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx@@ -54,6 +54,7 @@ import {useMediaMetadata} from '../../helpers/use-media-metadata';import {useRuntimeValueSelector} from '../../helpers/use-runtime-values';import {SnowflakeIcon} from '../../icons/snowflake';import {SetSelectedModalContext} from '../../state/modals';+import {TimelineZoomActiveContext} from '../../state/timeline-zoom';import {AudioWaveform} from '../AudioWaveform';import {CompositionOrStillIcon} from '../CompositionOrStillIcon';import {useConfirmationDialog} from '../ConfirmationDialog';@@ -286,42 +287,6 @@ type TimelineSequenceProps = {readonly parentVisibleEnd: number | null;};-const TimelineSequenceFn: React.FC<TimelineSequenceProps> = ({- s,- labelStartFrame,- connectedCompositions,- nodePathInfo,- keyframeDisplayOffset,- keyframePlaybackRate,- sequenceFrameOffset,- cascadedStart,- localStart,- parentVisibleStart,- parentVisibleEnd,-}) => {- const windowWidth = useContext(TimelineWidthContext);-- if (windowWidth === null) {- return null;- }-- return (- <MemoizedTimelineSequenceInner- s={s}- labelStartFrame={labelStartFrame}- connectedCompositions={connectedCompositions}- nodePathInfo={nodePathInfo}- keyframeDisplayOffset={keyframeDisplayOffset}- keyframePlaybackRate={keyframePlaybackRate}- sequenceFrameOffset={sequenceFrameOffset}- cascadedStart={cascadedStart}- localStart={localStart}- parentVisibleStart={parentVisibleStart}- parentVisibleEnd={parentVisibleEnd}- />- );-};-const TimelineSequenceNegativeStartInner: React.FC<{readonly left: number;readonly width: number;@@ -2040,8 +2005,6 @@ const TimelineSequenceInner: React.FC<TimelineSequenceProps> = (props) => {return <TimelineSequenceLayout state={state} />;};-const MemoizedTimelineSequenceInner = React.memo(TimelineSequenceInner);-const TimelineSequenceLayout: React.FC<{readonly state: ReturnType<typeof useTimelineSequenceState>;}> = ({state}) => {@@ -2114,6 +2077,7 @@ const TimelineSequenceLayoutInner: React.FC<{sourceTrimBlockedReason,onPointerEnter,} = state;+ const isZooming = useContext(TimelineZoomActiveContext);const sceneRange = useContext(TimelineSceneRangeContext);const inheritedSceneRange = useContext(TimelineInheritedSceneRangeContext);const sceneClipHeight = useContext(TimelineSceneClipHeightContext);@@ -2257,6 +2221,7 @@ const TimelineSequenceLayoutInner: React.FC<{const layerHeight = getTimelineSequenceHeight(s);const trimOutline = (() => {if (+ isZooming ||!isEdgeDragging ||!showTrimOutline ||activeEdgeHighlight === null ||@@ -2631,89 +2596,91 @@ const TimelineSequenceLayoutInner: React.FC<{onPointerEnter={onPointerEnter}onClick={onSequenceClick}edgeDragHandles={- <div- style={{- position: 'absolute',- inset: 0,- pointerEvents: 'none',- zIndex: 2,- }}- >- {showLeftActions && nodePathInfo ? (- <TimelineSequenceLeftEdgeDragHandle- // Transition targets keep the default cursor, including during rolling edits.- cursor={- s.timelineTrack?.role === 'transition'- ? 'default'- : `${timelineTrimEdgeCursor}, ew-resize`- }- trimBeforeCursor={`${timelineLeftEdgeCursor}, e-resize`}- sourceOnlyCursor={`${timelineSourceOnlyCursor}, ew-resize`}- edgeEnabled={leftTrimEnabled}- edgeBlockedReason={leftTrimBlockedReason}- sourceTrimBlockedReason={sourceTrimBlockedReason}- handleLayout={trimHandleLayout}- edgeOffset={leftEdgeOffset}- edgeMode={- isTransitionSeriesSequence(s) ? 'head-trim' : 'self-trim'- }- rollingEnabled={rollingEnabled}- fillTarget={s.timelineTrack?.role === 'transition'}- isTransitionSeries={- isTransitionSeriesSequence(s) ||- s.timelineTrack?.role === 'transition'- }- onHoverEnd={clearEdgeHighlight}- secondaryAction={secondaryLeftEdgeAction}- nodePathInfo={nodePathInfo}- windowWidth={windowWidth}- timelineDurationInFrames={video.durationInFrames ?? 1}- initialEdgeFrame={- s.from +- (s.timelineTrack?.role === 'transition' ? s.duration / 2 : 0)- }- fps={video.fps}- onDragStart={startLeftEdgeDrag}- onDragEnd={endEdgeDrag}- onLimitChange={onTrimLimitChange}- onSelect={onSelect}- selected={selected}- />- ) : null}- {showRightActions &&- trimHandleLayout.rightTrim !== null &&- nodePathInfo ? (- <TimelineSequenceRightEdgeDragHandle- isTransitionSeries={isTransitionSeriesSequence(s)}- handleLeft={trimHandleLayout.rightTrim!}- edgeOffset={rightEdgeOffset}- onHoverEnd={clearEdgeHighlight}- cursor={`${timelineRightEdgeCursor}, ew-resize`}- nodePathInfo={nodePathInfo}- mediaDurationDragLimits={mediaDurationDragLimits}- windowWidth={windowWidth}- timelineDurationInFrames={video.durationInFrames ?? 1}- initialEdgeFrame={- outgoingTransitionStart ??- s.from +- Math.max(- 0,- Math.min(- displayDurationInFrames,- effectiveMaxMediaDuration ?? Infinity,- video.durationInFrames - s.from,- ),- )- }- fps={video.fps}- onDragStart={startRightEdgeDrag}- onDragEnd={endEdgeDrag}- onLimitChange={onTrimLimitChange}- onSelect={onSelect}- selected={selected}- />- ) : null}- </div>+ isZooming && !isEdgeDragging ? null : (+ <div+ style={{+ position: 'absolute',+ inset: 0,+ pointerEvents: 'none',+ zIndex: 2,+ }}+ >+ {showLeftActions && nodePathInfo ? (+ <TimelineSequenceLeftEdgeDragHandle+ // Transition targets keep the default cursor, including during rolling edits.+ cursor={+ s.timelineTrack?.role === 'transition'+ ? 'default'+ : `${timelineTrimEdgeCursor}, ew-resize`+ }+ trimBeforeCursor={`${timelineLeftEdgeCursor}, e-resize`}+ sourceOnlyCursor={`${timelineSourceOnlyCursor}, ew-resize`}+ edgeEnabled={leftTrimEnabled}+ edgeBlockedReason={leftTrimBlockedReason}+ sourceTrimBlockedReason={sourceTrimBlockedReason}+ handleLayout={trimHandleLayout}+ edgeOffset={leftEdgeOffset}+ edgeMode={+ isTransitionSeriesSequence(s) ? 'head-trim' : 'self-trim'+ }+ rollingEnabled={rollingEnabled}+ fillTarget={s.timelineTrack?.role === 'transition'}+ isTransitionSeries={+ isTransitionSeriesSequence(s) ||+ s.timelineTrack?.role === 'transition'+ }+ onHoverEnd={clearEdgeHighlight}+ secondaryAction={secondaryLeftEdgeAction}+ nodePathInfo={nodePathInfo}+ windowWidth={windowWidth}+ timelineDurationInFrames={video.durationInFrames ?? 1}+ initialEdgeFrame={+ s.from ++ (s.timelineTrack?.role === 'transition' ? s.duration / 2 : 0)+ }+ fps={video.fps}+ onDragStart={startLeftEdgeDrag}+ onDragEnd={endEdgeDrag}+ onLimitChange={onTrimLimitChange}+ onSelect={onSelect}+ selected={selected}+ />+ ) : null}+ {showRightActions &&+ trimHandleLayout.rightTrim !== null &&+ nodePathInfo ? (+ <TimelineSequenceRightEdgeDragHandle+ isTransitionSeries={isTransitionSeriesSequence(s)}+ handleLeft={trimHandleLayout.rightTrim!}+ edgeOffset={rightEdgeOffset}+ onHoverEnd={clearEdgeHighlight}+ cursor={`${timelineRightEdgeCursor}, ew-resize`}+ nodePathInfo={nodePathInfo}+ mediaDurationDragLimits={mediaDurationDragLimits}+ windowWidth={windowWidth}+ timelineDurationInFrames={video.durationInFrames ?? 1}+ initialEdgeFrame={+ outgoingTransitionStart ??+ s.from ++ Math.max(+ 0,+ Math.min(+ displayDurationInFrames,+ effectiveMaxMediaDuration ?? Infinity,+ video.durationInFrames - s.from,+ ),+ )+ }+ fps={video.fps}+ onDragStart={startRightEdgeDrag}+ onDragEnd={endEdgeDrag}+ onLimitChange={onTrimLimitChange}+ onSelect={onSelect}+ selected={selected}+ />+ ) : null}+ </div>+ )}>{s.type === 'audio' && visibleLayout.media ? (@@ -2795,4 +2762,4 @@ const TimelineSequenceLayoutInner: React.FC<{);};-export const TimelineSequence = React.memo(TimelineSequenceFn);+export const TimelineSequence = React.memo(TimelineSequenceInner);diff --git a/packages/studio/src/components/Timeline/TimelineTrack.tsx b/packages/studio/src/components/Timeline/TimelineTrack.tsxindex e51766da2d..7797ad7fc7 100644--- a/packages/studio/src/components/Timeline/TimelineTrack.tsx+++ b/packages/studio/src/components/Timeline/TimelineTrack.tsx@@ -13,10 +13,20 @@ import {TimelineWidthContext} from './TimelineWidthProvider';const emptyConnectedCompositions = [] as const;+const TimelineTrackHighlight: React.FC<{readonly background: string}> = ({+ background,+}) => {+ const timelineWidth = useContext(TimelineWidthContext);+ return timelineWidth === null ? null : (+ <div+ style={getTimelineSelectedTrackHighlightStyle(timelineWidth, background)}+ />+ );+};+const TimelineTrackUnmemoized: React.FC<{readonly track: TimelineTrackData;}> = ({track}) => {- const timelineWidth = useContext(TimelineWidthContext);const {hovered, onPointerEnter, onPointerLeave} = useTimelineSequenceHover(track.nodePathInfo,);@@ -40,13 +50,8 @@ const TimelineTrackUnmemoized: React.FC<{return (<div onPointerEnter={onPointerEnter} onPointerLeave={onPointerLeave}><div style={layerStyle}>- {rowHighlightBackground && timelineWidth !== null ? (- <div- style={getTimelineSelectedTrackHighlightStyle(- timelineWidth,- rowHighlightBackground,- )}- />+ {rowHighlightBackground ? (+ <TimelineTrackHighlight background={rowHighlightBackground} />) : null}<TimelineSequences={track.sequence}diff --git a/packages/studio/src/components/Timeline/TimelineTracks.tsx b/packages/studio/src/components/Timeline/TimelineTracks.tsxindex 5f26b534e2..4667f41a0d 100644--- a/packages/studio/src/components/Timeline/TimelineTracks.tsx+++ b/packages/studio/src/components/Timeline/TimelineTracks.tsx@@ -68,9 +68,7 @@ const TimelineTrackRow: React.FC<{readonly row: TimelineVirtualRow;readonly start: number;readonly height: number;- readonly windowWidth: number | null;- readonly durationInFrames: number | null;-}> = React.memo(({row, start, height, windowWidth, durationInFrames}) => {+}> = React.memo(({row, start, height}) => {const {sceneRange, track, items, auxiliaryRows, auxiliaryRowOffsets} = row;const {getIsExpanded} = useContext(ExpandedTracksGetterContext);const {previewServerState} = useContext(StudioServerConnectionCtx);@@ -95,6 +93,49 @@ const TimelineTrackRow: React.FC<{/>);+ return (+ <TimelineTrackRowLayout+ sceneRange={sceneRange}+ start={start}+ height={height}+ clippedHeight={clippedHeight}+ keyframes={+ showExpandedKeyframes && track.nodePathInfo ? (+ <TimelineExpandedTrackKeyframes+ sequence={track.sequence}+ nodePathInfo={track.nodePathInfo}+ keyframeDisplayOffset={track.keyframeDisplayOffset}+ keyframePlaybackRate={track.keyframePlaybackRate}+ />+ ) : null+ }+ >+ {sceneRange === null ? (+ trackContent+ ) : (+ <TimelineSceneTrackContent+ sceneRange={sceneRange}+ height={clippedHeight}+ >+ {trackContent}+ </TimelineSceneTrackContent>+ )}+ </TimelineTrackRowLayout>+ );+});++// Only horizontal geometry subscribes to width; track contents stay stable.+const TimelineTrackRowLayout: React.FC<{+ readonly sceneRange: TimelineSceneRange | null;+ readonly start: number;+ readonly height: number;+ readonly clippedHeight: number;+ readonly children: React.ReactNode;+ readonly keyframes: React.ReactNode;+}> = ({sceneRange, start, height, clippedHeight, children, keyframes}) => {+ const windowWidth = useContext(TimelineWidthContext);+ const video = Internals.useUnsafeVideoConfig();+ const durationInFrames = video?.durationInFrames ?? null;return (<divstyle={{@@ -130,35 +171,17 @@ const TimelineTrackRow: React.FC<{: null}>- {sceneRange === null ? (- trackContent- ) : (- <TimelineSceneTrackContent- sceneRange={sceneRange}- height={clippedHeight}- >- {trackContent}- </TimelineSceneTrackContent>- )}+ {children}</TimelineTrimOutlineContainer>- {/* Keyframes own the full row, including positions outside the scene. */}- {showExpandedKeyframes && track.nodePathInfo ? (- <TimelineExpandedTrackKeyframes- sequence={track.sequence}- nodePathInfo={track.nodePathInfo}- keyframeDisplayOffset={track.keyframeDisplayOffset}- keyframePlaybackRate={track.keyframePlaybackRate}- />- ) : null}+ {keyframes}</div>);-});+};const TimelineTracksInner: React.FC<{readonly hasBeenCut: boolean;}> = ({hasBeenCut}) => {const {rows, tracksEnd, virtualItems} = useTimelineVirtualization();- const video = Internals.useUnsafeVideoConfig();const windowWidth = useContext(TimelineWidthContext);const renderWindow = useContext(TimelineViewportContext);useImperativeHandle(timelineDurationRef, () => ({@@ -218,8 +241,6 @@ const TimelineTracksInner: React.FC<{row={rows[virtualItem.index]}start={virtualItem.start}height={virtualItem.size}- windowWidth={windowWidth}- durationInFrames={video?.durationInFrames ?? null}/>))}</div>diff --git a/packages/studio/src/components/Timeline/TimelineTrimOutline.tsx b/packages/studio/src/components/Timeline/TimelineTrimOutline.tsxindex c5ddf94795..1ecf0582fb 100644--- a/packages/studio/src/components/Timeline/TimelineTrimOutline.tsx+++ b/packages/studio/src/components/Timeline/TimelineTrimOutline.tsx@@ -6,6 +6,7 @@ import React, {useState,} from 'react';import {createPortal} from 'react-dom';+import {TimelineZoomActiveContext} from '../../state/timeline-zoom';const originStyle: React.CSSProperties = {position: 'absolute',@@ -52,6 +53,7 @@ const TimelineTrimPortal: React.FC<{readonly children: React.ReactNode;readonly targetRef: React.RefObject<HTMLDivElement | null> | null;}> = ({children, targetRef}) => {+ const isZooming = useContext(TimelineZoomActiveContext);const originRef = useRef<HTMLDivElement>(null);const [placement, setPlacement] = useState<{readonly target: HTMLDivElement;@@ -62,6 +64,10 @@ const TimelineTrimPortal: React.FC<{} | null>(null);useLayoutEffect(() => {+ if (isZooming) {+ return;+ }+const target = targetRef?.current;const origin = originRef.current;if (!target || !origin) {@@ -88,16 +94,16 @@ const TimelineTrimPortal: React.FC<{? previous: next,);- }, [children, targetRef]);+ }, [children, isZooming, targetRef]);if (targetRef === null) {- return children;+ return isZooming ? null : children;}return (<><div ref={originRef} style={originStyle} />- {placement === null+ {isZooming || placement === null? null: createPortal(<divdiff --git a/packages/studio/src/components/Timeline/TimelineVirtualization.tsx b/packages/studio/src/components/Timeline/TimelineVirtualization.tsxindex 8bfae375c4..0e56508dc7 100644--- a/packages/studio/src/components/Timeline/TimelineVirtualization.tsx+++ b/packages/studio/src/components/Timeline/TimelineVirtualization.tsx@@ -16,6 +16,7 @@ import React, {} from 'react';import type {TSequence} from 'remotion';import {TIMELINE_ITEM_BORDER_BOTTOM} from '../../helpers/timeline-layout';+import {TimelineZoomActiveContext} from '../../state/timeline-zoom';import {MAX_TIMELINE_TRACKS_NOTICE_HEIGHT} from './MaxTimelineTracks';import {timelineVerticalScroll} from './timeline-refs';import {@@ -37,6 +38,8 @@ import {TIMELINE_TIME_INDICATOR_HEIGHT} from './TimelineTimeIndicators';import {useCompactSeries} from './use-compact-series';import {useTimelineTrackHeights} from './use-timeline-height';+const ZOOM_VERTICAL_OVERSCAN = 32;+export type TimelineVirtualRow = TimelineDisplayRow & {readonly auxiliaryRowOffsets: readonly number[];readonly afterDropLineOffset: number;@@ -76,6 +79,7 @@ export const TimelineVirtualizationProvider: React.FC<{readonly sequences: readonly TSequence[];};}> = ({children, hasBeenCut, isStill, timeline, layoutSnapshot}) => {+ const isZooming = useContext(TimelineZoomActiveContext);const compactSeries = useCompactSeries();const representativeTracks = useMemo(() => timeline.map((row) => row.track),@@ -233,8 +237,12 @@ export const TimelineVirtualizationProvider: React.FC<{// tall Series. Maintain a buffered row window inside it as well.const height = element.clientHeight;const section = Math.floor((element.scrollTop + height / 2) / height);- const top = Math.max(0, (section - 1) * height);- const bottom = top + height * 3;+ const top = isZooming+ ? Math.max(0, element.scrollTop - ZOOM_VERTICAL_OVERSCAN)+ : Math.max(0, (section - 1) * height);+ const bottom = isZooming+ ? element.scrollTop + height + ZOOM_VERTICAL_OVERSCAN+ : top + height * 3;setVerticalRenderWindow((previous) =>previous?.top === top && previous.bottom === bottom? previous@@ -258,7 +266,7 @@ export const TimelineVirtualizationProvider: React.FC<{resizeObserver?.disconnect();element?.removeEventListener('scroll', update);};- }, [hasSharedRows]);+ }, [hasSharedRows, isZooming]);const groupsRef = useRef(layout.groups);groupsRef.current = layout.groups;const timelineRef = useRef(timeline);@@ -299,7 +307,7 @@ export const TimelineVirtualizationProvider: React.FC<{estimateSize,getItemKey,getScrollElement,- overscan: 20,+ overscan: isZooming ? 1 : 20,paddingEnd,paddingStart,rangeExtractor,@@ -442,46 +450,61 @@ export const TimelineVirtualizationProvider: React.FC<{}, [consumeRevealRequest, revealRequest]);const virtualGroups = virtualizer.getVirtualItems();- const virtualItems = useMemo(- () =>- virtualGroups.flatMap((group) =>- layout.groups[group.index].rows- .filter((index) => {- if (- layout.groups[group.index].rows.length === 1 ||- selectedTrackIndexes.has(index)- ) {- return true;- }-+ const virtualItems = useMemo(() => {+ // Apply the smaller window in the first zoom commit, before the scroll+ // listener's next update. Keep selected rows mounted for ongoing edits.+ const element = timelineVerticalScroll.current;+ const zoomTop = (element?.scrollTop ?? 0) - ZOOM_VERTICAL_OVERSCAN;+ const zoomBottom =+ (element?.scrollTop ?? 0) ++ (element?.clientHeight ?? 0) ++ ZOOM_VERTICAL_OVERSCAN;+ return virtualGroups.flatMap((group) =>+ layout.groups[group.index].rows+ .filter((index) => {+ if (selectedTrackIndexes.has(index)) {+ return true;+ }++ if (isZooming && element !== null) {return (- verticalRenderWindow !== null &&- layout.offsets[index] < verticalRenderWindow.bottom &&- layout.offsets[index] + layout.rowHeights[index] >- verticalRenderWindow.top+ layout.offsets[index] < zoomBottom &&+ layout.offsets[index] + layout.rowHeights[index] > zoomTop);- })- .map(- (index): VirtualItem => ({- index,- key: layoutSnapshot.timeline[index].track.sequence.id,- start: layout.offsets[index],- end: layout.offsets[index] + layout.rowHeights[index],- size: layout.rowHeights[index],- lane: 0,- }),- ),- ),- [- layout.groups,- layout.offsets,- layout.rowHeights,- selectedTrackIndexes,- layoutSnapshot,- verticalRenderWindow,- virtualGroups,- ],- );+ }++ if (layout.groups[group.index].rows.length === 1) {+ return true;+ }++ return (+ verticalRenderWindow !== null &&+ layout.offsets[index] < verticalRenderWindow.bottom &&+ layout.offsets[index] + layout.rowHeights[index] >+ verticalRenderWindow.top+ );+ })+ .map(+ (index): VirtualItem => ({+ index,+ key: layoutSnapshot.timeline[index].track.sequence.id,+ start: layout.offsets[index],+ end: layout.offsets[index] + layout.rowHeights[index],+ size: layout.rowHeights[index],+ lane: 0,+ }),+ ),+ );+ }, [+ isZooming,+ layout.groups,+ layout.offsets,+ layout.rowHeights,+ selectedTrackIndexes,+ layoutSnapshot,+ verticalRenderWindow,+ virtualGroups,+ ]);const value = useMemo((): TimelineVirtualizationContextValue => ({rows: layout.rows,diff --git a/packages/studio/src/components/Timeline/TimelineZoomControls.tsx b/packages/studio/src/components/Timeline/TimelineZoomControls.tsxindex a43d68b8d1..714f7d5453 100644--- a/packages/studio/src/components/Timeline/TimelineZoomControls.tsx+++ b/packages/studio/src/components/Timeline/TimelineZoomControls.tsx@@ -1,5 +1,5 @@import {PlayerInternals} from '@remotion/player';-import React, {useCallback, useContext} from 'react';+import React, {useCallback, useContext, useEffect} from 'react';import {Internals} from 'remotion';import {BLACK} from '../../helpers/colors';import {@@ -22,6 +22,16 @@ import {Spacing} from '../layout';import {scrollableRef} from './timeline-refs';const TIMELINE_ZOOM_BUTTON_FACTOR = 1.2;+const timelineZoomKeys = [+ 'ArrowLeft',+ 'ArrowRight',+ 'ArrowUp',+ 'ArrowDown',+ 'PageUp',+ 'PageDown',+ 'Home',+ 'End',+];const container: React.CSSProperties = {color: BLACK,@@ -40,6 +50,8 @@ const TimelineZoomSlider: React.FC<{readonly timelineViewportWidth: number;}> = ({maxWidth, minZoom, timelineViewportWidth}) => {const {setZoom, zoom: zoomMap} = useContext(TimelineZoomCtx);+ const {beginZoom, endZoom} = useContext(TimelineZoomImperativeContext);+ useEffect(() => endZoom, [endZoom]);const videoConfig = Internals.useUnsafeVideoConfig();const {tabIndex} = useZIndex();const isVideoComposition = useIsVideoComposition();@@ -88,6 +100,28 @@ const TimelineZoomSlider: React.FC<{step={TIMELINE_ZOOM_SLIDER_PROPS.step}value={timelineZoomToSliderValue({zoom, minZoom})}onChange={onChange}+ onPointerDown={(event) => {+ if (event.button !== 0) {+ return;+ }++ event.currentTarget.setPointerCapture(event.pointerId);+ beginZoom();+ }}+ onPointerUp={endZoom}+ onPointerCancel={endZoom}+ onLostPointerCapture={endZoom}+ onBlur={endZoom}+ onKeyDown={(event) => {+ if (timelineZoomKeys.includes(event.key)) {+ beginZoom();+ }+ }}+ onKeyUp={(event) => {+ if (timelineZoomKeys.includes(event.key)) {+ endZoom();+ }+ }}className="__remotion-timeline-slider"tabIndex={tabIndex}/>diff --git a/packages/studio/src/components/Timeline/use-series-reorder.ts b/packages/studio/src/components/Timeline/use-series-reorder.tsindex fb76aa3e65..fcf30d675e 100644--- a/packages/studio/src/components/Timeline/use-series-reorder.ts+++ b/packages/studio/src/components/Timeline/use-series-reorder.ts@@ -14,6 +14,7 @@ import {reorderSequence} from '../reorder-sequence-api';import type {TimelineTrackWithDisplayGroup} from './timeline-display-groups';import {scrollableRef} from './timeline-refs';import {+ getTimelineContentWidth,SCROLL_INCREMENT,startTimelineEdgeAutoScroll,} from './timeline-scroll-logic';@@ -21,7 +22,6 @@ import {isTimelineSelectionModifierEvent,useCurrentTimelineSelectionStateAsRef,} from './TimelineSelection';-import {TimelineWidthContext} from './TimelineWidthProvider';const SERIES_REORDER_SEAM_SNAP_DISTANCE = 12;@@ -29,7 +29,6 @@ export const useSeriesReorder = (items: readonly TimelineTrackWithDisplayGroup[],) => {const {previewServerState} = useContext(StudioServerConnectionCtx);- const timelineWidth = useContext(TimelineWidthContext);const video = Internals.useVideo();const currentSelection = useCurrentTimelineSelectionStateAsRef();const [dropIndicatorLeft, setDropIndicatorLeft] = useState<number | null>(@@ -44,13 +43,14 @@ export const useSeriesReorder = (const onPointerDownCapture = useCallback((e: React.PointerEvent<HTMLDivElement>) => {+ const timelineWidth = getTimelineContentWidth();if (e.button !== 0 ||!e.isPrimary ||isTimelineSelectionModifierEvent(e) ||!isStudioInteractivityEnabled() ||previewServerState.type !== 'connected' ||- timelineWidth === null ||+ timelineWidth <= TIMELINE_PADDING * 2 ||video === null ||!(e.target instanceof Element) ||e.target.closest('button, input, textarea, select, [role="separator"]')@@ -329,7 +329,7 @@ export const useSeriesReorder = (},});},- [currentSelection, items, previewServerState, timelineWidth, video],+ [currentSelection, items, previewServerState, video],);const onClickCapture = useCallback((e: React.MouseEvent<HTMLDivElement>) => {if (suppressNextClick.current) {diff --git a/packages/studio/src/state/timeline-zoom.tsx b/packages/studio/src/state/timeline-zoom.tsxindex efdc804e37..82f7801c53 100644--- a/packages/studio/src/state/timeline-zoom.tsx+++ b/packages/studio/src/state/timeline-zoom.tsx@@ -1,6 +1,7 @@import React, {createContext,useCallback,+ useEffect,useLayoutEffect,useMemo,useRef,@@ -41,12 +42,18 @@ export const TimelineZoomCtx = createContext<TimelineZoomContextValue>({},});+export const TimelineZoomActiveContext = createContext(false);+export const TimelineZoomImperativeContext = createContext<Pick<TimelineZoomContextValue, 'setZoom'> & {getZoom: (videoId: string) => number | null;+ beginZoom: () => void;+ endZoom: () => void;}>({getZoom: () => null,+ beginZoom: () => undefined,+ endZoom: () => undefined,setZoom: () => {throw new Error('has no context');},@@ -55,6 +62,36 @@ export const TimelineZoomImperativeContext = createContext<export const TimelineZoomContext: React.FC<{readonly children: React.ReactNode;}> = ({children}) => {+ const [isZooming, setIsZooming] = useState(false);+ const zoomHeld = useRef(false);+ const zoomIdleTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);+ const endZoom = useCallback(() => {+ zoomHeld.current = false;+ if (zoomIdleTimeout.current !== null) {+ clearTimeout(zoomIdleTimeout.current);+ zoomIdleTimeout.current = null;+ }++ setIsZooming(false);+ }, []);+ const beginZoom = useCallback(() => {+ zoomHeld.current = true;+ if (zoomIdleTimeout.current !== null) {+ clearTimeout(zoomIdleTimeout.current);+ zoomIdleTimeout.current = null;+ }++ setIsZooming(true);+ }, []);+ useEffect(() => {+ window.addEventListener('blur', endZoom);+ return () => {+ window.removeEventListener('blur', endZoom);+ if (zoomIdleTimeout.current !== null) {+ clearTimeout(zoomIdleTimeout.current);+ }+ };+ }, [endZoom]);const [zoom, setZoomState] = useState<Record<string, number>>(() =>getZoomFromLocalStorage(),);@@ -78,6 +115,7 @@ export const TimelineZoomContext: React.FC<{});flushSync(() => {+ setIsZooming(true);setZoomState((prevZoomMap) => {const durationInFrames = getCurrentDuration();const timelineViewportWidth = scrollableRef.current?.clientWidth ?? 0;@@ -102,8 +140,17 @@ export const TimelineZoomContext: React.FC<{// A large zoom can move beyond the old horizontal render window. Commit// the new window before the browser paints the new scroll position.flushSync(syncTimelineViewport);+ // Wheel events and zoom buttons have no explicit interaction end.+ // Slider drags and native pinch gestures keep the interaction held.+ if (zoomIdleTimeout.current !== null) {+ clearTimeout(zoomIdleTimeout.current);+ }++ if (!zoomHeld.current) {+ zoomIdleTimeout.current = setTimeout(endZoom, 150);+ }},- [],+ [endZoom],);const value = useMemo(() => {@@ -116,13 +163,17 @@ export const TimelineZoomContext: React.FC<{return {getZoom: (videoId: string) => zoomRef.current[videoId] ?? null,setZoom,+ beginZoom,+ endZoom,};- }, [setZoom]);+ }, [beginZoom, endZoom, setZoom]);return (<TimelineZoomCtx.Provider value={value}><TimelineZoomImperativeContext.Provider value={imperativeValue}>- {children}+ <TimelineZoomActiveContext.Provider value={isZooming}>+ {children}+ </TimelineZoomActiveContext.Provider></TimelineZoomImperativeContext.Provider></TimelineZoomCtx.Provider>);