Skip to content

🎥 Make videos programmatically with React

`remotion`: Keep Studio timeline setters free of dummy frame refs

Noah Lindnerc36823815608
diff --git a/packages/core/src/TimelineContext.tsx b/packages/core/src/TimelineContext.tsx
index 434e7d2f9f..6d95b24479 100644
--- a/packages/core/src/TimelineContext.tsx
+++ b/packages/core/src/TimelineContext.tsx
@@ -29,9 +29,9 @@ export type SetTimelineContextValue = {
setFrame: (u: React.SetStateAction<Record<string, number>>) => void;
setPlaying: (u: React.SetStateAction<boolean>) => void;
subscribePlaying: (listener: () => void) => () => void;
- frameRef: RefObject<Record<string, number>>;
- isPlaying: () => boolean;
- audioAndVideoTags: RefObject<PlayableMediaTag[]>;
+ frameRef: RefObject<Record<string, number>> | null;
+ isPlaying: (() => boolean) | null;
+ audioAndVideoTags: RefObject<PlayableMediaTag[]> | null;
};
export const SetTimelineContext = createContext<SetTimelineContextValue>({
@@ -44,11 +44,9 @@ export const SetTimelineContext = createContext<SetTimelineContextValue>({
subscribePlaying: () => {
throw new Error('default');
},
- frameRef: {current: {}},
- isPlaying: () => {
- throw new Error('default');
- },
- audioAndVideoTags: {current: []},
+ frameRef: null,
+ isPlaying: null,
+ audioAndVideoTags: null,
});
export const TimelineContext = createContext<TimelineContextValue | null>(null);
@@ -60,8 +58,6 @@ export const AbsoluteTimeContext = createContext<TimelineContextValue | null>(
null,
);
-const studioFrameRef: RefObject<Record<string, number>> = {current: {}};
-
export const TimelineContextProvider: React.FC<{
readonly children: React.ReactNode;
readonly frameState: Record<string, number> | null;
@@ -148,11 +144,11 @@ export const TimelineContextProvider: React.FC<{
}
},
subscribePlaying: playingStore.store.subscribe,
- frameRef: studioFrameRef,
- isPlaying: readIsPlaying,
- audioAndVideoTags,
+ frameRef: null,
+ isPlaying: null,
+ audioAndVideoTags: null,
};
- }, [playingStore, readIsPlaying]);
+ }, [playingStore]);
return (
<AbsoluteTimeContext.Provider value={timelineContextValue}>
diff --git a/packages/player/src/use-player-methods.ts b/packages/player/src/use-player-methods.ts
index 1d3abf30e7..3f0b65e2eb 100644
--- a/packages/player/src/use-player-methods.ts
+++ b/packages/player/src/use-player-methods.ts
@@ -40,6 +40,12 @@ export const usePlayerMethods = (): UsePlayerMethods => {
throw new TypeError('Expected Player event emitter context');
}
+ if (!frameRef || !readIsPlaying || !audioAndVideoTags) {
+ throw new Error(
+ 'Player timeline context is not available. This hook must be used inside a <Player>.',
+ );
+ }
+
const bufferingContext = useContext(Internals.BufferingContextReact);
if (!bufferingContext) {
throw new Error(