Skip to content

🎥 Make videos programmatically with React

should fix node / nextjs player example

Jonny Burger83b2280ca1eb
diff --git a/packages/core/src/use-lazy-component.ts b/packages/core/src/use-lazy-component.ts
index a0c77013c4..4aacbd70f5 100644
--- a/packages/core/src/use-lazy-component.ts
+++ b/packages/core/src/use-lazy-component.ts
@@ -2,11 +2,9 @@ import React, {useMemo} from 'react';
import {CompProps} from './internals';
// Expected, it can be any component props
-export const useLazyComponent = (
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- compProps: CompProps<any>
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
-): React.LazyExoticComponent<React.ComponentType<any>> => {
+export const useLazyComponent = <T>(
+ compProps: CompProps<T>
+): React.LazyExoticComponent<React.ComponentType<T>> => {
const lazy = useMemo(() => {
if ('lazyComponent' in compProps) {
return React.lazy(compProps.lazyComponent);
@@ -16,8 +14,7 @@ export const useLazyComponent = (
// In SSR, suspense is not yet supported, we cannot use React.lazy
if (typeof document === 'undefined') {
return (compProps.component as unknown) as React.LazyExoticComponent<
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- React.ComponentType<any>
+ React.ComponentType<T>
>;
}
@@ -25,8 +22,12 @@ export const useLazyComponent = (
}
throw new Error("You must pass either 'component' or 'lazyComponent'");
+
+ // Very important to leave the dependencies as they are, or instead
+ // the player will remount on every frame.
+
// @ts-expect-error
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [compProps.lazyComponent, compProps.component]);
+ }, [compProps.component, compProps.lazyComponent]);
return lazy;
};
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index cbe1b0cb6c..9469a4d774 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -93,13 +93,15 @@ export const PlayerFn = <T,>(
return {
compositions: [
{
- component,
+ component: component as React.LazyExoticComponent<
+ React.ComponentType<unknown>
+ >,
durationInFrames,
height,
width,
fps,
id: 'player-comp',
- props: inputProps,
+ props: inputProps as unknown,
nonce: 777,
},
],
diff --git a/packages/player/src/PlayerUI.tsx b/packages/player/src/PlayerUI.tsx
index d6d6277f1b..dde8ea87fa 100644
--- a/packages/player/src/PlayerUI.tsx
+++ b/packages/player/src/PlayerUI.tsx
@@ -289,7 +289,7 @@ const PlayerUI: React.ForwardRefRenderFunction<
) : null}
</div>
);
- // Don't render suspense on
+ // Don't render suspense on Node.js
if (IS_NODE) {
return content;
}
diff --git a/packages/player/src/utils/is-node.ts b/packages/player/src/utils/is-node.ts
index 148b73e9da..6f825167e4 100644
--- a/packages/player/src/utils/is-node.ts
+++ b/packages/player/src/utils/is-node.ts
@@ -1,4 +1 @@
-export const IS_NODE =
- typeof process !== 'undefined' &&
- process.versions !== null &&
- process.versions.node !== null;
+export const IS_NODE = typeof document === 'undefined';