Skip to content

🎥 Make videos programmatically with React

still works

Jonny Burgerbfaaf78235b6
diff --git a/packages/bundler/src/homepage/homepage.tsx b/packages/bundler/src/homepage/homepage.tsx
index cf30c35529..250c121fcc 100644
--- a/packages/bundler/src/homepage/homepage.tsx
+++ b/packages/bundler/src/homepage/homepage.tsx
@@ -170,10 +170,15 @@ const TestCORS: React.FC = () => {
);
};
-export const Homepage: React.FC = () => {
+export const Homepage: React.FC<{
+ rootComponent: React.FC;
+}> = ({rootComponent}) => {
const url = window.location.origin + window.location.pathname;
+
+ const Root = rootComponent;
return (
<div style={container}>
+ <Root />
<h1>Remotion Bundle</h1>
This is a website which contains a bundled Remotion video. You can render
videos based on this URL.
diff --git a/packages/bundler/src/renderEntry.tsx b/packages/bundler/src/renderEntry.tsx
index b277750fa5..a8b7696076 100644
--- a/packages/bundler/src/renderEntry.tsx
+++ b/packages/bundler/src/renderEntry.tsx
@@ -146,29 +146,6 @@ const videoContainer = document.getElementById(
'video-container',
) as HTMLElement;
-const WaitForRoot: React.FC = () => {
- const [Root, setRoot] = useState<React.FC | null>(() => Internals.getRoot());
-
- useEffect(() => {
- if (Root) {
- continueRender(waitForRootHandle);
- return;
- }
-
- const cleanup = Internals.waitForRoot((NewRoot) => {
- setRoot(() => NewRoot);
- });
-
- return () => cleanup();
- }, [Root]);
-
- if (Root === null) {
- return null;
- }
-
- return <Root />;
-};
-
let root: ReturnType<typeof ReactDOM.createRoot> | null = null;
const getRootForElement = () => {
@@ -192,13 +169,13 @@ const renderToDOM = (content: React.ReactElement) => {
}
};
-const renderContent = () => {
+const renderContent = (Root: React.FC) => {
const bundleMode = getBundleMode();
if (bundleMode.type === 'composition') {
const markup = (
<Internals.RemotionRoot numberOfAudioTags={0}>
- <WaitForRoot />
+ <Root />
<GetVideo state={bundleMode} />
</Internals.RemotionRoot>
);
@@ -210,10 +187,10 @@ const renderContent = () => {
const markup = (
<>
<Internals.RemotionRoot numberOfAudioTags={0}>
- <WaitForRoot />
+ <Root />
<GetVideo state={bundleMode} />
</Internals.RemotionRoot>
- <Homepage />
+ <Homepage rootComponent={Root} />
</>
);
@@ -221,15 +198,20 @@ const renderContent = () => {
}
if (bundleMode.type === 'index') {
- renderToDOM(<Homepage />);
+ renderToDOM(<Homepage rootComponent={Root} />);
}
};
-renderContent();
+Internals.waitForRoot((Root) => {
+ renderContent(Root);
+ continueRender(waitForRootHandle);
+});
export const setBundleModeAndUpdate = (state: BundleState) => {
setBundleMode(state);
- renderContent();
+ Internals.waitForRoot((Root) => {
+ renderContent(Root);
+ });
};
if (typeof window !== 'undefined') {