Skip to content

🎥 Make videos programmatically with React

don't call useLayoutEffect on server in next.js

Jonny Burgerc0f8310c1bb2
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index c78a4d9d09..84e0b75564 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -339,12 +339,15 @@ 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')
- );
- }, []);
+ if (typeof window !== 'undefined') {
+ // eslint-disable-next-line react-hooks/rules-of-hooks
+ 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>