🎥 Make videos programmatically with React
improve on hook change
Jonny Burger16039674352b
diff --git a/packages/bundler/src/error-overlay/entry-basic.ts b/packages/bundler/src/error-overlay/entry-basic.tsindex 95af74b9a6..6042d05a16 100644--- a/packages/bundler/src/error-overlay/entry-basic.ts+++ b/packages/bundler/src/error-overlay/entry-basic.ts@@ -1,4 +1,4 @@-import {shouldReload, startReportingRuntimeErrors} from './react-overlay';+import {didUnmountReactApp, startReportingRuntimeErrors} from './react-overlay';import {mountRemotionOverlay} from './remotion-overlay';import {setErrorsRef} from './remotion-overlay/Overlay';@@ -6,7 +6,7 @@ startReportingRuntimeErrors(() => {if (module.hot) {module.hot.addStatusHandler((status) => {if (status === 'apply') {- if (shouldReload()) {+ if (didUnmountReactApp()) {return window.location.reload();}diff --git a/packages/bundler/src/error-overlay/react-overlay/index.ts b/packages/bundler/src/error-overlay/react-overlay/index.tsindex 8128d5b347..ec8d5ae531 100644--- a/packages/bundler/src/error-overlay/react-overlay/index.ts+++ b/packages/bundler/src/error-overlay/react-overlay/index.ts@@ -3,7 +3,7 @@ import {listenToRuntimeErrors} from './listen-to-runtime-errors';let stopListeningToRuntimeErrors: null | (() => void) = null;-export const shouldReload = () => {+export const didUnmountReactApp = () => {return !Internals.getPreviewDomElement()?.hasChildNodes();};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.tsindex a831515ad0..bed103ec30 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@@ -53,9 +53,18 @@ export const getErrorRecord = async (};const crashWithFrames = (crash: () => void) => (error: Error) => {- setErrorsRef.current?.addError(error);+ const didHookOrderChange =+ error.message.startsWith('Rendered fewer hooks') ||+ error.message.startsWith('Rendered more hooks');- crash();+ if (didHookOrderChange) {+ console.log('Hook order changed. Reloading app...');+ window.location.reload();+ } else {+ setErrorsRef.current?.addError(error);++ crash();+ }};export function listenToRuntimeErrors(crash: () => void) {diff --git a/packages/bundler/src/error-overlay/remotion-overlay/ErrorTitle.tsx b/packages/bundler/src/error-overlay/remotion-overlay/ErrorTitle.tsxindex ec2240c404..96dd6d7fca 100644--- a/packages/bundler/src/error-overlay/remotion-overlay/ErrorTitle.tsx+++ b/packages/bundler/src/error-overlay/remotion-overlay/ErrorTitle.tsx@@ -1,5 +1,5 @@-import React from 'react';-import {shouldReload} from '../react-overlay';+import React, {useMemo, useState} from 'react';+import {didUnmountReactApp} from '../react-overlay';import {DismissButton} from './DismissButton';import {Symbolicating} from './Symbolicating';@@ -58,7 +58,7 @@ export const ErrorTitle: React.FC<{<div>{message}</div></div></div>- {shouldReload() ? null : <DismissButton />}+ {didUnmountReactApp() ? null : <DismissButton />}</div>);};diff --git a/packages/bundler/src/hot-middleware/client.ts b/packages/bundler/src/hot-middleware/client.tsindex 6e93f1fa25..b92dc54989 100644--- a/packages/bundler/src/hot-middleware/client.ts+++ b/packages/bundler/src/hot-middleware/client.ts@@ -41,7 +41,6 @@ function eventSourceWrapper() {}function handleOnline() {- console.log('[Fast Refresh] connected');lastActivity = Date.now();}