Skip to content

🎥 Make videos programmatically with React

Update Player.tsx

Jonny Burger4957f53c89a3
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index 0e85d93433..d9ecd705e0 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -61,10 +61,6 @@ export type PlayerProps<T> = {
} & PropsIfHasProps<T> &
CompProps<T>;
-Internals.CSSUtils.injectCSS(
- Internals.CSSUtils.makeDefaultCSS(`.${PLAYER_CSS_CLASSNAME}`, '#fff')
-);
-
export const componentOrNullIfLazy = <T,>(
props: CompProps<T>
): ComponentType<T> | null => {
@@ -341,6 +337,13 @@ export const PlayerFn = <T,>(
return inputProps ?? {};
}, [inputProps]);
+ useLayoutEffect(() => {
+ // Inject CSS only on client, and also only after the Player has hydrated
+ Internals.CSSUtils.injectCSS(
+ Internals.CSSUtils.makeDefaultCSS(`.${PLAYER_CSS_CLASSNAME}`, '#fff')
+ );
+ }, []);
+
return (
<Internals.CanUseRemotionHooksProvider>
<Internals.Timeline.TimelineContext.Provider value={timelineContextValue}>