Skip to content

🎥 Make videos programmatically with React

interesting

Jonny Burger1d8b6a569bd4
diff --git a/packages/bundler/src/error-overlay/entry-basic.ts b/packages/bundler/src/error-overlay/entry-basic.ts
index df2c2af4f4..8c98e3817e 100644
--- a/packages/bundler/src/error-overlay/entry-basic.ts
+++ b/packages/bundler/src/error-overlay/entry-basic.ts
@@ -1,16 +1,15 @@
import {startReportingRuntimeErrors} from './react-overlay';
+import {mountRemotionOverlay} from './remotion-overlay';
startReportingRuntimeErrors({
onError() {
if (module.hot) {
- console.log('error occurred');
module.hot.addStatusHandler((status) => {
if (status === 'apply') {
- console.log('apply');
- // window.location.reload();
- // dismissRuntimeErrors();
+ window.location.reload();
}
});
}
},
});
+mountRemotionOverlay();
diff --git a/packages/bundler/src/error-overlay/react-overlay/index.ts b/packages/bundler/src/error-overlay/react-overlay/index.ts
index 9682730a2d..3f30dace17 100644
--- a/packages/bundler/src/error-overlay/react-overlay/index.ts
+++ b/packages/bundler/src/error-overlay/react-overlay/index.ts
@@ -1,3 +1,4 @@
+import {setErrorsRef} from '../remotion-overlay/Overlay';
import {ErrorRecord, listenToRuntimeErrors} from './listen-to-runtime-errors';
let stopListeningToRuntimeErrors: null | (() => void) = null;
@@ -15,6 +16,7 @@ export function startReportingRuntimeErrors(options: RuntimeReportingOptions) {
const handleRuntimeError =
(opts: RuntimeReportingOptions) => (errorRecord: ErrorRecord) => {
+ console.log('err');
try {
if (typeof opts.onError === 'function') {
opts.onError.call(null);
@@ -37,11 +39,12 @@ export function startReportingRuntimeErrors(options: RuntimeReportingOptions) {
};
function update() {
+ setErrorsRef.current?.setErrors(currentRuntimeErrorRecords);
console.log('do something', currentRuntimeErrorRecords);
}
stopListeningToRuntimeErrors = listenToRuntimeErrors(
handleRuntimeError(options),
- options.filename
+ options.filename as string
);
}
diff --git a/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.ts b/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.ts
index ec7edce06e..8833c64bfe 100644
--- a/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.ts
+++ b/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.ts
@@ -64,7 +64,7 @@ export const crashWithFrames =
export function listenToRuntimeErrors(
crash: (rec: ErrorRecord) => void,
- filename = '/static/js/bundle.js'
+ filename: string
) {
const crashWithFramesRunTime = crashWithFrames(crash);
@@ -73,6 +73,7 @@ export function listenToRuntimeErrors(
registerStackTraceLimit();
registerReactStack();
permanentRegisterConsole('error', (warning, stack) => {
+ console.log('errrr');
const data = massageWarning(warning, stack);
crashWithFramesRunTime(
{
diff --git a/packages/bundler/src/error-overlay/remotion-overlay/ErrorDisplay.tsx b/packages/bundler/src/error-overlay/remotion-overlay/ErrorDisplay.tsx
new file mode 100644
index 0000000000..65b08e7229
--- /dev/null
+++ b/packages/bundler/src/error-overlay/remotion-overlay/ErrorDisplay.tsx
@@ -0,0 +1,71 @@
+import React from 'react';
+import {ErrorRecord} from '../react-overlay/listen-to-runtime-errors';
+
+const container: React.CSSProperties = {
+ width: '100%',
+ maxWidth: 1000,
+ marginLeft: 'auto',
+ marginRight: 'auto',
+ fontFamily: 'sans-serif',
+ paddingTop: '5vh',
+};
+
+const title: React.CSSProperties = {
+ fontSize: '1.5em',
+ fontWeight: 'bold',
+};
+
+const stack: React.CSSProperties = {
+ backgroundColor: 'black',
+ marginTop: 17,
+};
+
+const stackLine: React.CSSProperties = {
+ paddingTop: 8,
+ paddingBottom: 8,
+ paddingLeft: 14,
+ paddingRight: 14,
+};
+
+export const ErrorDisplay: React.FC<{
+ display: ErrorRecord;
+}> = ({display}) => {
+ return (
+ <div style={container}>
+ <div style={title}>
+ {display.error.name}: {display.error.message}
+ </div>
+ <div style={stack}>
+ {display.stackFrames.map((s, i) => {
+ return (
+ // eslint-disable-next-line react/no-array-index-key
+ <div key={i} style={stackLine}>
+ <div>{s.functionName}</div>
+ <div>
+ {s._originalFileName}:{s.columnNumber}
+ </div>
+ <div>
+ {s._originalScriptCode?.map((s, j) => {
+ return (
+ <div
+ // eslint-disable-next-line react/no-array-index-key
+ key={j}
+ style={{
+ fontFamily: 'monospace',
+ whiteSpace: 'pre',
+ tabSize: 2,
+ color: s.highlight ? 'red' : 'inherit',
+ }}
+ >
+ {s.content}
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ );
+};
diff --git a/packages/bundler/src/error-overlay/remotion-overlay/Overlay.tsx b/packages/bundler/src/error-overlay/remotion-overlay/Overlay.tsx
new file mode 100644
index 0000000000..7f7c5fb6d7
--- /dev/null
+++ b/packages/bundler/src/error-overlay/remotion-overlay/Overlay.tsx
@@ -0,0 +1,36 @@
+import React, {createRef, useImperativeHandle, useState} from 'react';
+import {AbsoluteFill} from 'remotion';
+import {ErrorRecord} from '../react-overlay/listen-to-runtime-errors';
+import {ErrorDisplay} from './ErrorDisplay';
+
+type SetErrors = {
+ setErrors: (errs: ErrorRecord[]) => void;
+};
+
+export const setErrorsRef = createRef<SetErrors>();
+
+export const Overlay: React.FC = () => {
+ const [errors, setErrors] = useState<ErrorRecord[]>([]);
+
+ useImperativeHandle(
+ setErrorsRef,
+ () => {
+ return {setErrors};
+ },
+ []
+ );
+
+ if (errors.length === 0) {
+ return null;
+ }
+
+ return (
+ <AbsoluteFill
+ style={{backgroundColor: '#1f2428', overflow: 'auto', color: 'white'}}
+ >
+ {errors.map((err) => {
+ return <ErrorDisplay key={err.error.stack} display={err} />;
+ })}
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/bundler/src/error-overlay/remotion-overlay/index.tsx b/packages/bundler/src/error-overlay/remotion-overlay/index.tsx
new file mode 100644
index 0000000000..d1638d2a1e
--- /dev/null
+++ b/packages/bundler/src/error-overlay/remotion-overlay/index.tsx
@@ -0,0 +1,9 @@
+import ReactDOM from 'react-dom';
+import {Overlay} from './Overlay';
+
+export const mountRemotionOverlay = () => {
+ ReactDOM.render(
+ <Overlay />,
+ document.getElementById('remotion-error-overlay')
+ );
+};
diff --git a/packages/bundler/src/static-preview.ts b/packages/bundler/src/static-preview.ts
index d3daea256c..ca0f8fe3d2 100644
--- a/packages/bundler/src/static-preview.ts
+++ b/packages/bundler/src/static-preview.ts
@@ -18,6 +18,7 @@ export const indexHtml = (staticHash: string) =>
<div id="menuportal-3"></div>
<div id="menuportal-4"></div>
<div id="menuportal-5"></div>
+ <div id="remotion-error-overlay"></div>
<script src="/bundle.js"></script>
</body>
</html>
diff --git a/packages/example/src/HackerLogo/index.tsx b/packages/example/src/HackerLogo/index.tsx
index 4c531ad4bc..1655d16bb2 100644
--- a/packages/example/src/HackerLogo/index.tsx
+++ b/packages/example/src/HackerLogo/index.tsx
@@ -12,7 +12,7 @@ const HackerLogo: React.FC = () => {
fontFamily: 'Roboto Condensed',
}}
>
- <span style={{color: 'white'}}>HACKER</span>
+ <span style={{color: 'white'}}>HACK</span>
</div>
);
};