🎥 Make videos programmatically with React
fix arrow keys after loading studio
Jonny Burger5030f3e747ce
diff --git a/packages/core/src/RemotionRoot.tsx b/packages/core/src/RemotionRoot.tsxindex bdfcf4bbab..87de224061 100644--- a/packages/core/src/RemotionRoot.tsx+++ b/packages/core/src/RemotionRoot.tsx@@ -19,6 +19,7 @@ import type {TimelineContextValue,} from './timeline-position-state.js';import {+ getInitialFrameState,SetTimelineContext,TimelineContext,} from './timeline-position-state.js';@@ -35,7 +36,9 @@ export const RemotionRoot: React.FC<{numberOfAudioTags: number;}> = ({children, numberOfAudioTags}) => {const [remotionRootId] = useState(() => String(random(null)));- const [frame, setFrame] = useState<Record<string, number>>({});+ const [frame, setFrame] = useState<Record<string, number>>(() =>+ getInitialFrameState(),+ );const [playing, setPlaying] = useState<boolean>(false);const imperativePlaying = useRef<boolean>(false);const [fastRefreshes, setFastRefreshes] = useState(0);diff --git a/packages/core/src/timeline-position-state.ts b/packages/core/src/timeline-position-state.tsindex 27964009f4..cd392b4dfd 100644--- a/packages/core/src/timeline-position-state.ts+++ b/packages/core/src/timeline-position-state.ts@@ -45,18 +45,28 @@ export const SetTimelineContext = createContext<SetTimelineContextValue>({},});-const makeKey = (composition: string) => {- return `remotion.time.${composition}`;+type CurrentTimePerComposition = Record<string, number>;++const makeKey = () => {+ return `remotion.time-all`;+};++export const persistCurrentFrame = (time: CurrentTimePerComposition) => {+ localStorage.setItem(makeKey(), JSON.stringify(time));};-export const persistCurrentFrame = (frame: number, composition: string) => {- localStorage.setItem(makeKey(composition), String(frame));+export const getInitialFrameState = () => {+ const item = localStorage.getItem(makeKey()) ?? '{}';+ const obj: CurrentTimePerComposition = JSON.parse(item);+ return obj;};export const getFrameForComposition = (composition: string) => {- const frame = localStorage.getItem(makeKey(composition));- return frame- ? Number(frame)+ const item = localStorage.getItem(makeKey()) ?? '{}';+ const obj: CurrentTimePerComposition = JSON.parse(item);++ return obj[composition]+ ? Number(obj[composition]): (typeof window === 'undefined' ? 0 : window.remotion_initialFrame ?? 0) ??0;};diff --git a/packages/studio/src/components/FramePersistor.tsx b/packages/studio/src/components/FramePersistor.tsxindex f32002faba..9631cc148b 100644--- a/packages/studio/src/components/FramePersistor.tsx+++ b/packages/studio/src/components/FramePersistor.tsx@@ -6,11 +6,16 @@ export const FramePersistor: React.FC = () => {const [playing] = Internals.Timeline.usePlayingState();const config = useVideoConfig();const frame = Internals.Timeline.useTimelinePosition();+ const setFrame = Internals.useTimelineSetFrame();useEffect(() => {if (!playing) {- Internals.persistCurrentFrame(frame, config.id);+ setFrame((f) => {+ const newObj = {...f, [config.id]: frame};+ Internals.persistCurrentFrame(newObj);+ return newObj;+ });}- }, [config.id, frame, playing]);+ }, [config.id, frame, playing, setFrame]);return null;};diff --git a/packages/studio/src/components/Timeline/TimelineDragHandler.tsx b/packages/studio/src/components/Timeline/TimelineDragHandler.tsxindex d8c8f8ac66..25b868dbf3 100644--- a/packages/studio/src/components/Timeline/TimelineDragHandler.tsx+++ b/packages/studio/src/components/Timeline/TimelineDragHandler.tsx@@ -416,8 +416,11 @@ const Inner: React.FC = () => {extrapolate: 'clamp',});- Internals.persistCurrentFrame(frame, videoConfig.id);- setFrame((c) => ({...c, [videoConfig.id]: frame}));+ setFrame((c) => {+ const newObj = {...c, [videoConfig.id]: frame};+ Internals.persistCurrentFrame(newObj);+ return newObj;+ });if (dragging.wasPlaying) {play();