Skip to content

🎥 Make videos programmatically with React

Docs: Update Player in iFrame snippet

Jonny Burger3ff622e90449
diff --git a/packages/docs/docs/miscellaneous/snippets/player-in-iframe.md b/packages/docs/docs/miscellaneous/snippets/player-in-iframe.md
index 34f7dff58f..7674171299 100644
--- a/packages/docs/docs/miscellaneous/snippets/player-in-iframe.md
+++ b/packages/docs/docs/miscellaneous/snippets/player-in-iframe.md
@@ -20,43 +20,33 @@ This snippet is useful if you want to isolate the global styles of your homepage
```tsx title="IframePlayer.tsx"
import { Player, PlayerProps, PlayerRef } from "@remotion/player";
-import React, {
- forwardRef,
- MutableRefObject,
- useEffect,
- useRef,
- useState,
-} from "react";
+import React, { forwardRef, useEffect, useRef, useState } from "react";
import ReactDOM from "react-dom";
+import { AnyZodObject } from "zod";
const className = "__player";
const borderNone: React.CSSProperties = {
border: "none",
};
-const IframePlayerWithoutRef = <T,>(
- props: PlayerProps<T>,
- ref: MutableRefObject<PlayerRef>
+const IframePlayerWithoutRef = <T extends Record<string, unknown>>(
+ props: PlayerProps<AnyZodObject, T>,
+ ref: React.Ref<PlayerRef>
) => {
const [contentRef, setContentRef] = useState<HTMLIFrameElement | null>(null);
const resizeObserverRef = useRef<ResizeObserver | null>(null);
-
const mountNode = contentRef?.contentDocument?.body;
-
useEffect(() => {
if (!contentRef || !contentRef.contentDocument) return;
-
// Remove margin and padding so player fits snugly
contentRef.contentDocument.body.style.margin = "0";
contentRef.contentDocument.body.style.padding = "0";
-
// When player div is resized also resize iframe
resizeObserverRef.current = new ResizeObserver(([playerEntry]) => {
const playerRect = playerEntry.contentRect;
contentRef.width = String(playerRect.width);
contentRef.height = String(playerRect.height);
});
-
// The remotion player element
const playerElement = contentRef.contentDocument.querySelector(
"." + className
@@ -77,22 +67,23 @@ const IframePlayerWithoutRef = <T,>(
);
};
}, [contentRef]);
-
const combinedClassName = `${className} ${props.className ?? ""}`.trim();
-
return (
// eslint-disable-next-line @remotion/warn-native-media-tag
<iframe ref={setContentRef} style={borderNone}>
{mountNode &&
ReactDOM.createPortal(
// @ts-expect-error PlayerProps are incorrectly typed
- <Player<T> {...props} ref={ref} className={combinedClassName} />,
+ <Player<AnyZodObject, T>
+ {...props}
+ ref={ref}
+ className={combinedClassName}
+ />,
mountNode
)}
</iframe>
);
};
-
export const IframePlayer = forwardRef(IframePlayerWithoutRef);
```
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index 428992705d..9b08a30963 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -392,7 +392,7 @@ const forward = forwardRef as <T, P = {}>(
) => (props: P & React.RefAttributes<T>) => React.ReactElement | null;
/**
- * @description A component which can be rendered in a regular React App (for example: Create React App, Next.js) to display a Remotion video.
+ * @description A component which can be rendered in a regular React App (for example: Vite, Next.js) to display a Remotion video.
* @see [Documentation](https://www.remotion.dev/docs/player/player)
*/
export const Player = forward(PlayerFn);