🎥 Make videos programmatically with React
`@remotion/studio`: Prevent collapsed timeline frame errors (#8823)
Jonny Burgerb2deb6a70564
diff --git a/packages/studio/src/components/Timeline/timeline-scroll-logic.ts b/packages/studio/src/components/Timeline/timeline-scroll-logic.tsindex 6fb754a1e7..c262ecf230 100644--- a/packages/studio/src/components/Timeline/timeline-scroll-logic.ts+++ b/packages/studio/src/components/Timeline/timeline-scroll-logic.ts@@ -229,7 +229,11 @@ export const getFrameIncrementFromWidth = (durationInFrames: number,width: number,) => {- return (width - TIMELINE_PADDING * 2) / durationInFrames;+ return getUsableTimelineWidth(width) / durationInFrames;+};++const getUsableTimelineWidth = (width: number) => {+ return Math.max(1, width - TIMELINE_PADDING * 2);};export const getFrameWhileScrollingRight = ({@@ -272,7 +276,7 @@ export const getFrameFromX = ({Math.round(interpolate(pos,- [0, width - TIMELINE_PADDING * 2],+ [0, getUsableTimelineWidth(width)],[0, durationInFrames],{extrapolateLeft: extrapolate,diff --git a/packages/studio/src/test/timeline-scroll-logic.test.ts b/packages/studio/src/test/timeline-scroll-logic.test.tsnew file mode 100644index 0000000000..2cc1cb24c8--- /dev/null+++ b/packages/studio/src/test/timeline-scroll-logic.test.ts@@ -0,0 +1,20 @@+import {expect, test} from 'bun:test';+import {+ getFrameFromX,+ getFrameIncrementFromWidth,+} from '../components/Timeline/timeline-scroll-logic';++test('getFrameFromX handles collapsed timeline widths', () => {+ expect(+ getFrameFromX({+ clientX: 0,+ durationInFrames: 100,+ extrapolate: 'clamp',+ width: 0,+ }),+ ).toBe(0);+});++test('getFrameIncrementFromWidth never returns a negative increment', () => {+ expect(getFrameIncrementFromWidth(100, 0)).toBe(0.01);+});