Skip to content

🎥 Make videos programmatically with React

ask user to handle timeout themselves

Jonny Burgere3b80c77e71f
diff --git a/packages/bundler/src/renderEntry.tsx b/packages/bundler/src/renderEntry.tsx
index 7d0674deb5..b30fb4460a 100644
--- a/packages/bundler/src/renderEntry.tsx
+++ b/packages/bundler/src/renderEntry.tsx
@@ -31,13 +31,6 @@ const GetVideo: React.FC<{state: BundleState}> = ({state}) => {
const video = Internals.useVideo();
const compositions = useContext(Internals.CompositionManager);
const [Root, setRoot] = useState<React.FC | null>(() => Internals.getRoot());
- const [waitForRoot] = useState(() => {
- if (Root) {
- return 0;
- }
-
- return delayRender('Waiting for registerRoot()');
- });
const [Component, setComponent] = useState<ComponentType<unknown> | null>(
null
@@ -87,12 +80,6 @@ const GetVideo: React.FC<{state: BundleState}> = ({state}) => {
}
}, [Component, state.type]);
- useEffect(() => {
- if (Root) {
- continueRender(waitForRoot);
- }
- }, [Component, Root, video, waitForRoot]);
-
useEffect(() => {
if (!video) {
return;
@@ -119,7 +106,7 @@ const GetVideo: React.FC<{state: BundleState}> = ({state}) => {
});
return () => cleanup();
- }, [Root, waitForRoot]);
+ }, [Root]);
if (!Root) {
return null;
@@ -232,6 +219,12 @@ export const setBundleModeAndUpdate = (state: BundleState) => {
if (typeof window !== 'undefined') {
window.getStaticCompositions = (): TCompMetadata[] => {
+ if (!Internals.getRoot()) {
+ throw new Error(
+ 'registerRoot() was never called. 1. Make sure you specified the correct entrypoint for your bundle. 2. If your registerRoot() call is deferred, use the delayRender/continueRender pattern to tell Remotion to wait.'
+ );
+ }
+
if (!Internals.compositionsRef.current) {
throw new Error('Unexpectedly did not have a CompositionManager');
}
diff --git a/packages/cli/src/editor/components/Editor.tsx b/packages/cli/src/editor/components/Editor.tsx
index d6e92284f3..f258e51228 100644
--- a/packages/cli/src/editor/components/Editor.tsx
+++ b/packages/cli/src/editor/components/Editor.tsx
@@ -38,6 +38,7 @@ import {FramePersistor} from './FramePersistor';
import {GlobalKeybindings} from './GlobalKeybindings';
import {KeyboardShortcuts} from './KeyboardShortcutsModal';
import NewComposition from './NewComposition/NewComposition';
+import {NoRegisterRoot} from './NoRegisterRoot';
import {UpdateModal} from './UpdateModal/UpdateModal';
const background: React.CSSProperties = {
@@ -203,7 +204,11 @@ export const Editor: React.FC = () => {
<div style={background}>
{Root === null ? null : <Root />}
<FramePersistor />
- <EditorContent />
+ {Root === null ? (
+ <NoRegisterRoot />
+ ) : (
+ <EditorContent />
+ )}
<GlobalKeybindings />
</div>
{modalContextType &&
diff --git a/packages/cli/src/editor/components/NoRegisterRoot.tsx b/packages/cli/src/editor/components/NoRegisterRoot.tsx
new file mode 100644
index 0000000000..0f3a0c27a5
--- /dev/null
+++ b/packages/cli/src/editor/components/NoRegisterRoot.tsx
@@ -0,0 +1,58 @@
+import React, {useEffect, useState} from 'react';
+
+const label: React.CSSProperties = {
+ fontSize: 13,
+ color: 'white',
+ fontFamily: 'Arial, Helvetica, sans-serif',
+};
+
+const container: React.CSSProperties = {
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'center',
+ flex: 1,
+ flexDirection: 'column',
+ textAlign: 'center',
+ lineHeight: 1.5,
+};
+
+const link: React.CSSProperties = {
+ color: 'white',
+ textDecoration: 'none',
+ borderBottom: '1px solid',
+};
+
+export const NoRegisterRoot: React.FC = () => {
+ const [show, setShow] = useState(() => false);
+
+ useEffect(() => {
+ // Only show after 2 seconds so there is no flicker when the load is really fast
+ const timeout = setTimeout(() => {
+ setShow(true);
+ }, 2000);
+
+ return () => {
+ clearTimeout(timeout);
+ };
+ }, []);
+
+ if (!show) {
+ return null;
+ }
+
+ return (
+ <div style={container}>
+ <div style={label}>Waiting for registerRoot() to get called.</div>
+ <div style={label}>
+ Learn more:{' '}
+ <a
+ target={'_blank'}
+ style={link}
+ href="https://www.remotion.dev/docs/register-root"
+ >
+ remotion.dev/docs/register-root
+ </a>
+ </div>
+ </div>
+ );
+};
diff --git a/packages/example/src/index.tsx b/packages/example/src/index.tsx
index 9ccc5b137d..a4a22bf371 100644
--- a/packages/example/src/index.tsx
+++ b/packages/example/src/index.tsx
@@ -1,6 +1,9 @@
-import {registerRoot} from 'remotion';
+import {continueRender, delayRender, registerRoot} from 'remotion';
import {Index} from './Video';
+// Should be able to defer registerRoot()
+const waitForRoot = delayRender('Waiting for root');
setTimeout(() => {
registerRoot(Index);
+ continueRender(waitForRoot);
}, 500);