Skip to content

🎥 Make videos programmatically with React

simplification

Jonny Burger8c2d18ac0e9c
diff --git a/packages/bundler/src/error-overlay/entry-basic.ts b/packages/bundler/src/error-overlay/entry-basic.ts
index a623cf1021..18ddcc5c6a 100644
--- a/packages/bundler/src/error-overlay/entry-basic.ts
+++ b/packages/bundler/src/error-overlay/entry-basic.ts
@@ -6,22 +6,20 @@ import {
import {mountRemotionOverlay} from './remotion-overlay';
import {setErrorsRef} from './remotion-overlay/Overlay';
-startReportingRuntimeErrors({
- onError() {
- if (module.hot) {
- module.hot.addStatusHandler((status) => {
- if (status === 'apply') {
- if (shouldReload()) {
- return window.location.reload();
- }
-
- dismissErrors();
- setErrorsRef.current?.setErrors({
- type: 'clear',
- });
+startReportingRuntimeErrors(() => {
+ if (module.hot) {
+ module.hot.addStatusHandler((status) => {
+ if (status === 'apply') {
+ if (shouldReload()) {
+ return window.location.reload();
}
- });
- }
- },
+
+ dismissErrors();
+ setErrorsRef.current?.setErrors({
+ type: 'clear',
+ });
+ }
+ });
+ }
});
mountRemotionOverlay();
diff --git a/packages/bundler/src/error-overlay/react-overlay/index.ts b/packages/bundler/src/error-overlay/react-overlay/index.ts
index 6b20ff94d5..4af65040db 100644
--- a/packages/bundler/src/error-overlay/react-overlay/index.ts
+++ b/packages/bundler/src/error-overlay/react-overlay/index.ts
@@ -3,9 +3,6 @@ import {setErrorsRef} from '../remotion-overlay/Overlay';
import {ErrorRecord, listenToRuntimeErrors} from './listen-to-runtime-errors';
let stopListeningToRuntimeErrors: null | (() => void) = null;
-type RuntimeReportingOptions = {
- onError: () => void;
-};
let currentRuntimeErrorRecords: ErrorRecord[] = [];
@@ -21,33 +18,30 @@ const errorsAreTheSame = (first: Error, second: Error) => {
return first.stack === second.stack && first.message === second.message;
};
-export function startReportingRuntimeErrors(options: RuntimeReportingOptions) {
+export function startReportingRuntimeErrors(onError: () => void) {
if (stopListeningToRuntimeErrors !== null) {
throw new Error('Already listening');
}
- const handleRuntimeError =
- (opts: RuntimeReportingOptions) => (errorRecord: ErrorRecord) => {
- try {
- if (typeof opts.onError === 'function') {
- opts.onError();
- }
- } finally {
- if (
- currentRuntimeErrorRecords.some(({error}) =>
- errorsAreTheSame(error, errorRecord.error)
- )
- ) {
- // Deduplicate identical errors.
- // This fixes https://github.com/facebook/create-react-app/issues/3011.
- } else {
- currentRuntimeErrorRecords = currentRuntimeErrorRecords.concat([
- errorRecord,
- ]);
- update();
- }
+ const handleRuntimeError = (errorRecord: ErrorRecord) => {
+ try {
+ onError();
+ } finally {
+ if (
+ currentRuntimeErrorRecords.some(({error}) =>
+ errorsAreTheSame(error, errorRecord.error)
+ )
+ ) {
+ // Deduplicate identical errors.
+ // This fixes https://github.com/facebook/create-react-app/issues/3011.
+ } else {
+ currentRuntimeErrorRecords = currentRuntimeErrorRecords.concat([
+ errorRecord,
+ ]);
+ update();
}
- };
+ }
+ };
function update() {
setErrorsRef.current?.setErrors({
@@ -56,7 +50,5 @@ export function startReportingRuntimeErrors(options: RuntimeReportingOptions) {
});
}
- stopListeningToRuntimeErrors = listenToRuntimeErrors(
- handleRuntimeError(options)
- );
+ stopListeningToRuntimeErrors = listenToRuntimeErrors(handleRuntimeError);
}
diff --git a/packages/bundler/src/error-overlay/react-overlay/utils/get-stack-frames.ts b/packages/bundler/src/error-overlay/react-overlay/utils/get-stack-frames.ts
index bd981ed666..e23fada0cd 100644
--- a/packages/bundler/src/error-overlay/react-overlay/utils/get-stack-frames.ts
+++ b/packages/bundler/src/error-overlay/react-overlay/utils/get-stack-frames.ts
@@ -13,26 +13,12 @@ import type {StackFrame} from './stack-frame';
import {parseError} from './parser';
import {unmap} from './unmapper';
-const getEnhancedFrames = async (
- parsedFrames: StackFrame[],
- contextSize: number
-): Promise<{
- frames: StackFrame[];
-}> => {
- return {
- frames: await unmap(parsedFrames, contextSize),
- };
-};
-
export const getStackFrames = async (
error: Error,
contextSize: number
): Promise<{frames: StackFrame[] | null}> => {
const parsedFrames = await parseError(error, contextSize);
- const {frames: enhancedFrames} = await getEnhancedFrames(
- parsedFrames,
- contextSize
- );
+ const enhancedFrames = await unmap(parsedFrames, contextSize);
if (
enhancedFrames
.map((f) => f.originalFileName)
@@ -48,10 +34,7 @@ export const getStackFrames = async (
return {
frames: enhancedFrames.filter(
- ({functionName}) =>
- functionName === null ||
- functionName === undefined ||
- functionName.indexOf('__stack_frame_overlay_proxy_console__') === -1
+ ({functionName}) => functionName === null || functionName === undefined
),
};
};