Skip to content

🎥 Make videos programmatically with React

demo error

Jonny Burger229f24c186f9
diff --git a/packages/docs/src/components/Demo/Demo.tsx b/packages/docs/src/components/Demo/Demo.tsx
index 7e26dc27ad..2c8b37fbb2 100644
--- a/packages/docs/src/components/Demo/Demo.tsx
+++ b/packages/docs/src/components/Demo/Demo.tsx
@@ -21,6 +21,7 @@ import {
getDataAndProps,
} from '../../remotion/HomepageVideo/Comp';
import type {Location} from '../../remotion/HomepageVideo/types';
+import {DemoError} from './DemoError';
import {RenderButton} from './DemoRender';
import {DownloadNudge} from './DownloadNudge';
import {DragAndDropNudge} from './DragAndDropNudge';
@@ -47,15 +48,21 @@ export const Demo: React.FC = () => {
const [data, setData] = useState<LocationAndTrending | null>(null);
const ref = useRef<PlayerRef>(null);
- useEffect(() => {
- getDataAndProps().then((d) => {
- setData(d);
- });
- }, []);
-
const [isFullscreen, setIsFullscreen] = useState(false);
const [cardOrder, setCardOrder] = useState([0, 1, 2, 3]);
const [emojiIndex, setEmojiIndex] = useState<number>(0);
+ const [error, setError] = useState(false);
+
+ useEffect(() => {
+ getDataAndProps()
+ .then((d) => {
+ setData(d);
+ })
+ .catch((err) => {
+ console.log(err);
+ setError(true);
+ });
+ }, []);
useEffect(() => {
const {current: playerRef} = ref;
@@ -140,6 +147,7 @@ export const Demo: React.FC = () => {
/>
</PlayerControls>
</div>
+ {error ? <DemoError /> : null}
<DownloadNudge />
</div>
);
diff --git a/packages/docs/src/components/Demo/DemoError.tsx b/packages/docs/src/components/Demo/DemoError.tsx
new file mode 100644
index 0000000000..f980a1930a
--- /dev/null
+++ b/packages/docs/src/components/Demo/DemoError.tsx
@@ -0,0 +1,18 @@
+import React from 'react';
+import {FONTS, RED} from '../../../components/layout/colors';
+
+export const DemoError: React.FC = () => {
+ return (
+ <div
+ style={{
+ color: RED,
+ fontFamily: FONTS.GTPLANAR,
+ position: 'absolute',
+ paddingTop: 15,
+ }}
+ >
+ Sorry, we limit the amount of renders possible per day on this page. Come
+ back tomorrow!
+ </div>
+ );
+};
diff --git a/packages/docs/src/components/Demo/DemoErrorIcon.tsx b/packages/docs/src/components/Demo/DemoErrorIcon.tsx
new file mode 100644
index 0000000000..52a5092307
--- /dev/null
+++ b/packages/docs/src/components/Demo/DemoErrorIcon.tsx
@@ -0,0 +1,33 @@
+import React from 'react';
+import {RED} from '../../../components/layout/colors';
+import styles from './done.module.css';
+
+export const DemoErrorIcon: React.FC = () => {
+ return (
+ <div
+ style={{
+ height: 26,
+ width: 26,
+ borderRadius: 13,
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ }}
+ className={styles.jump}
+ >
+ <svg
+ style={{
+ flexShrink: 0,
+ width: 26,
+ }}
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 512 512"
+ >
+ <path
+ fill={RED}
+ d="M17.1 292c-12.9-22.3-12.9-49.7 0-72L105.4 67.1c12.9-22.3 36.6-36 62.4-36l176.6 0c25.7 0 49.5 13.7 62.4 36L494.9 220c12.9 22.3 12.9 49.7 0 72L406.6 444.9c-12.9 22.3-36.6 36-62.4 36l-176.6 0c-25.7 0-49.5-13.7-62.4-36L17.1 292zM256 128c-13.3 0-24 10.7-24 24l0 112c0 13.3 10.7 24 24 24s24-10.7 24-24l0-112c0-13.3-10.7-24-24-24zm32 224a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z"
+ />
+ </svg>
+ </div>
+ );
+};
diff --git a/packages/docs/src/components/Demo/DemoRender.tsx b/packages/docs/src/components/Demo/DemoRender.tsx
index 7d30a91abd..f74f20b77b 100644
--- a/packages/docs/src/components/Demo/DemoRender.tsx
+++ b/packages/docs/src/components/Demo/DemoRender.tsx
@@ -2,6 +2,7 @@ import type {EnhancedErrorInfo} from '@remotion/lambda';
import React, {useCallback} from 'react';
import {z} from 'zod';
import {PALETTE} from '../../../components/layout/colors';
+import {DemoErrorIcon} from './DemoErrorIcon';
import {DoneCheckmark} from './DoneCheckmark';
import {Progress} from './Progress';
import {Spinner} from './Spinner';
@@ -47,6 +48,9 @@ type State =
}
| {
type: 'done';
+ }
+ | {
+ type: 'error';
};
const style: React.CSSProperties = {
@@ -74,49 +78,53 @@ export const RenderButton: React.FC<{
return;
}
- setState({type: 'invoking'});
-
- const {renderId, bucketName} = await (
- await fetch('https://bugs.remotion.dev/render', {
- method: 'post',
- headers: {'content-type': 'application/json'},
- body: JSON.stringify(renderData),
- })
- ).json();
- setState({type: 'progress', progress: 0});
-
- let done = false;
+ try {
+ setState({type: 'invoking'});
- while (!done) {
- const progress = (await (
- await fetch('https://bugs.remotion.dev/progress', {
+ const {renderId, bucketName} = await (
+ await fetch('https://bugs.remotion.dev/render', {
method: 'post',
headers: {'content-type': 'application/json'},
- body: JSON.stringify({renderId, bucketName}),
+ body: JSON.stringify(renderData),
})
- ).json()) as {
- overallProgress: number;
- outputFile: string | null;
- errors: EnhancedErrorInfo[];
- fatalErrorEncountered: boolean;
- };
- setState({
- type: 'progress',
- progress: progress.overallProgress,
- });
+ ).json();
+ setState({type: 'progress', progress: 0});
- if (progress.outputFile) {
- done = true;
- const a = document.createElement('a');
- a.href = progress.outputFile;
- a.download = 'remotion.dev.mp4';
- a.click();
- setState({type: 'done'});
- }
+ let done = false;
+
+ while (!done) {
+ const progress = (await (
+ await fetch('https://bugs.remotion.dev/progress', {
+ method: 'post',
+ headers: {'content-type': 'application/json'},
+ body: JSON.stringify({renderId, bucketName}),
+ })
+ ).json()) as {
+ overallProgress: number;
+ outputFile: string | null;
+ errors: EnhancedErrorInfo[];
+ fatalErrorEncountered: boolean;
+ };
+ setState({
+ type: 'progress',
+ progress: progress.overallProgress,
+ });
+
+ if (progress.outputFile) {
+ done = true;
+ const a = document.createElement('a');
+ a.href = progress.outputFile;
+ a.download = 'remotion.dev.mp4';
+ a.click();
+ setState({type: 'done'});
+ }
- if (progress.fatalErrorEncountered) {
- done = true;
+ if (progress.fatalErrorEncountered) {
+ done = true;
+ }
}
+ } catch (err) {
+ setState({type: 'error'});
}
}, [renderData]);
@@ -125,9 +133,11 @@ export const RenderButton: React.FC<{
type="button"
onClick={triggerRender}
style={style}
- disabled={!renderData}
+ disabled={!renderData || state.type !== 'idle'}
>
- {state.type === 'done' ? (
+ {state.type === 'error' ? (
+ <DemoErrorIcon />
+ ) : state.type === 'done' ? (
<DoneCheckmark />
) : state.type === 'progress' ? (
<Progress progress={state.progress} />