🎥 Make videos programmatically with React
get the logic
Rishi Raj Jainccbfbefa4222
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx b/packages/cli/src/editor/components/RenderModal/RenderModal.tsxindex 07735d7744..f7862f389f 100644--- a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx+++ b/packages/cli/src/editor/components/RenderModal/RenderModal.tsx@@ -50,6 +50,7 @@ import {ModalContainer,} from '../ModalContainer';import {NewCompHeader} from '../ModalHeader';+import {notificationCenter} from '../Notifications/NotificationCenter';import {optionsSidebarTabs,persistSelectedOptionsSidebarPanel,@@ -719,8 +720,21 @@ const RenderModal: React.FC<]);useEffect(() => {+ const listenToChanges = () => {+ if (window.unsavedProps) {+ notificationCenter.current?.addNotification({+ id: 'random',+ content: 'Do not save hey',+ created: new Date().getMilliseconds(),+ duration: 1,+ });+ }+ };++ window.addEventListener('beforeunload', listenToChanges);return () => {isMounted.current = false;+ window.removeEventListener('beforeunload', listenToChanges);};}, []);diff --git a/packages/cli/src/editor/helpers/document-title.ts b/packages/cli/src/editor/helpers/document-title.tsindex dadeed3c2e..cae902a367 100644--- a/packages/cli/src/editor/helpers/document-title.ts+++ b/packages/cli/src/editor/helpers/document-title.ts@@ -1,17 +1,27 @@-import type {RenderJob} from '../../preview-server/render-queue/job';-import {truthy} from '../../truthy';+import type { RenderJob } from '../../preview-server/render-queue/job';+import { truthy } from '../../truthy';let currentVideoId: string | null = null;let unsavedProps = false;let tabInactive = false;let renderJobs: RenderJob[] = [];+declare global {+ interface Window {+ unsavedProps: boolean;+ }+}+export const setCurrentVideoId = (id: string | null) => {currentVideoId = id;updateTitle();};export const setUnsavedProps = (unsaved: boolean) => {+ if (typeof window !== 'undefined') {+ window.unsavedProps = unsaved;+ }+unsavedProps = unsaved;};diff --git a/packages/cli/src/event-source.ts b/packages/cli/src/event-source.tsindex bf1c0628f5..3ce2ee236f 100644--- a/packages/cli/src/event-source.ts+++ b/packages/cli/src/event-source.ts@@ -1,7 +1,7 @@-import {sendErrorNotification} from './editor/components/Notifications/NotificationCenter';-import {renderJobsRef} from './editor/components/RenderQueue/context';-import {studioServerConnectionRef} from './editor/helpers/client-id';-import type {EventSourceEvent} from './event-source-events';+import { notificationCenter, sendErrorNotification } from './editor/components/Notifications/NotificationCenter';+import { renderJobsRef } from './editor/components/RenderQueue/context';+import { studioServerConnectionRef } from './editor/helpers/client-id';+import type { EventSourceEvent } from './event-source-events';let source: EventSource | null = null;@@ -14,7 +14,7 @@ export const subscribeToEvent = (type: EventSourceEvent['type'],listener: (event: EventSourceEvent) => void) => {- listeners.push({type, listener});+ listeners.push({ type, listener });return () => {listeners = listeners.filter(@@ -32,7 +32,17 @@ export const openEventSource = () => {newEvent.type === 'new-input-props' ||newEvent.type === 'new-env-variables') {- window.location.reload();+ if (window.unsavedProps) {+ notificationCenter.current?.addNotification({+ id: 'random',+ content: 'Do not save hey',+ created: new Date().getMilliseconds(),+ duration: 1+ })+ }+ else {+ window.location.reload();+ }}if (newEvent.type === 'init') {@@ -66,7 +76,7 @@ export const openEventSource = () => {(source as EventSource).addEventListener('error',() => {- studioServerConnectionRef.current?.set({type: 'disconnected'});+ studioServerConnectionRef.current?.set({ type: 'disconnected' });// Display an error message that the studio server has disconnected.source?.close();@@ -75,7 +85,7 @@ export const openEventSource = () => {openEventSource();}, 1000);},- {once: true}+ { once: true });});};diff --git a/packages/cli/src/preview-server/error-overlay/react-overlay/listen-to-runtime-errors.ts b/packages/cli/src/preview-server/error-overlay/react-overlay/listen-to-runtime-errors.tsindex 645f708b84..df9795c242 100644--- a/packages/cli/src/preview-server/error-overlay/react-overlay/listen-to-runtime-errors.ts+++ b/packages/cli/src/preview-server/error-overlay/react-overlay/listen-to-runtime-errors.ts@@ -1,5 +1,6 @@-import {setErrorsRef} from '../remotion-overlay/Overlay';-import {massageWarning} from './effects/format-warning';+import { notificationCenter } from '../../../editor/components/Notifications/NotificationCenter';+import { setErrorsRef } from '../remotion-overlay/Overlay';+import { massageWarning } from './effects/format-warning';import {permanentRegister as permanentRegisterConsole,registerReactStack,@@ -23,8 +24,8 @@ import {register as registerPromise,unregister as unregisterPromise,} from './effects/unhandled-rejection';-import {getStackFrames} from './utils/get-stack-frames';-import type {SymbolicatedStackFrame} from './utils/stack-frame';+import { getStackFrames } from './utils/get-stack-frames';+import type { SymbolicatedStackFrame } from './utils/stack-frame';export type ErrorRecord = {error: Error;@@ -72,7 +73,17 @@ const crashWithFrames = (crash: () => void) => (error: Error) => {if (didHookOrderChange && !justRefreshedBecauseOfHooks) {// eslint-disable-next-line no-consoleconsole.log('Hook order changed. Reloading app...');- window.location.reload();+ if (window.unsavedProps) {+ notificationCenter.current?.addNotification({+ id: 'random',+ content: 'Do not save hey',+ created: new Date().getMilliseconds(),+ duration: 1+ })+ }+ else {+ window.location.reload();+ }} else {setErrorsRef.current?.addError(error);@@ -97,7 +108,7 @@ export function listenToRuntimeErrors(crash: () => void) {registerReactStack();permanentRegisterConsole('error', (d) => {if (d.type === 'webpack-error') {- const {message, frames} = d;+ const { message, frames } = d;const data = massageWarning(message, frames);crashWithFramesRunTime({diff --git a/packages/cli/src/preview-server/hot-middleware/process-update.ts b/packages/cli/src/preview-server/hot-middleware/process-update.tsindex b9340cc7a6..2e7616a694 100644--- a/packages/cli/src/preview-server/hot-middleware/process-update.ts+++ b/packages/cli/src/preview-server/hot-middleware/process-update.ts@@ -11,7 +11,8 @@* Original copyright Tobias Koppers @sokra (MIT license)*/-import type {HotMiddlewareOptions, ModuleMap} from './types';+import { notificationCenter } from '../../editor/components/Notifications/NotificationCenter';+import type { HotMiddlewareOptions, ModuleMap } from './types';if (!__webpack_module__.hot) {throw new Error('[Fast refresh] Hot Module Replacement is disabled.');@@ -20,7 +21,7 @@ if (!__webpack_module__.hot) {const hmrDocsUrl = 'https://webpack.js.org/concepts/hot-module-replacement/'; // eslint-disable-line max-lenlet lastHash: string | undefined;-const failureStatuses = {abort: 1, fail: 1};+const failureStatuses = { abort: 1, fail: 1 };const applyOptions: AcceptOptions = {ignoreUnaccepted: true,ignoreDeclined: true,@@ -28,7 +29,7 @@ const applyOptions: AcceptOptions = {onUnaccepted(data) {console.warn('Ignored an update to unaccepted module ' +- (data.chain ?? []).join(' -> ')+ (data.chain ?? []).join(' -> '));},onDeclined(data) {@@ -40,10 +41,10 @@ const applyOptions: AcceptOptions = {console.error(data.error);console.warn('Ignored an error while updating module ' +- data.moduleId +- ' (' +- data.type +- ')'+ data.moduleId ++ ' (' ++ data.type ++ ')');},};@@ -58,7 +59,7 @@ export const processUpdate = function (moduleMap: ModuleMap,options: HotMiddlewareOptions) {- const {reload} = options;+ const { reload } = options;if (!upToDate(hash) && __webpack_module__.hot?.status() === 'idle') {check();}@@ -123,12 +124,12 @@ export const processUpdate = function (if (options.warn) {console.warn("[Fast refresh] The following modules couldn't be hot updated: " +- '(Full reload needed)\n' +- 'This is usually because the modules which have changed ' +- '(and their parents) do not know how to hot reload themselves. ' +- 'See ' +- hmrDocsUrl +- ' for more details.'+ '(Full reload needed)\n' ++ 'This is usually because the modules which have changed ' ++ '(and their parents) do not know how to hot reload themselves. ' ++ 'See ' ++ hmrDocsUrl ++ ' for more details.');unacceptedModules.forEach((moduleId) => {console.warn(@@ -169,7 +170,17 @@ export const processUpdate = function (console.warn('[Fast refresh] Update check failed: ' + (err.stack || err.message));- window.location.reload();+ if (window.unsavedProps) {+ notificationCenter.current?.addNotification({+ id: 'random',+ content: 'Do not save hey',+ created: new Date().getMilliseconds(),+ duration: 1+ })+ }+ else {+ window.location.reload();+ }}}@@ -179,6 +190,16 @@ export const processUpdate = function (}if (options.warn) console.warn('[Fast refresh] Reloading page');- window.location.reload();+ if (window.unsavedProps) {+ notificationCenter.current?.addNotification({+ id: 'random',+ content: 'Do not save hey',+ created: new Date().getMilliseconds(),+ duration: 1+ })+ }+ else {+ window.location.reload();+ }}};