Skip to content

🎥 Make videos programmatically with React

beforeunload in editor

Rishi Raj Jaind91d819e5aa2
diff --git a/packages/cli/src/editor/components/Editor.tsx b/packages/cli/src/editor/components/Editor.tsx
index 8639479de1..2b3e0b7e11 100644
--- a/packages/cli/src/editor/components/Editor.tsx
+++ b/packages/cli/src/editor/components/Editor.tsx
@@ -30,6 +30,20 @@ export const Editor: React.FC = () => {
return delayRender('Waiting for registerRoot()');
});
+ useEffect(() => {
+ const listenToChanges = (e: BeforeUnloadEvent) => {
+ if (window.remotion_unsavedProps) {
+ e.returnValue = 'Are you sure you want to leave?';
+ }
+ };
+
+ window.addEventListener('beforeunload', listenToChanges);
+
+ return () => {
+ window.removeEventListener('beforeunload', listenToChanges);
+ };
+ }, []);
+
useEffect(() => {
if (Root) {
return;
@@ -40,7 +54,9 @@ export const Editor: React.FC = () => {
continueRender(waitForRoot);
});
- return () => cleanup();
+ return () => {
+ cleanup();
+ };
}, [Root, waitForRoot]);
return (
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx b/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
index ac0a2df560..fc1fc580f5 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
@@ -51,7 +51,6 @@ import {
ModalContainer,
} from '../ModalContainer';
import {NewCompHeader} from '../ModalHeader';
-import {notificationCenter} from '../Notifications/NotificationCenter';
import {
optionsSidebarTabs,
persistSelectedOptionsSidebarPanel,
@@ -735,26 +734,6 @@ const RenderModal: React.FC<
onClose,
]);
- useEffect(() => {
- const listenToChanges = () => {
- if (window.remotion_unsavedProps) {
- notificationCenter.current?.addNotification({
- id: new Date().toString(),
- content:
- 'There are unsaved changes to the props. Do you want to leave?',
- created: new Date().getMilliseconds(),
- duration: 1,
- });
- }
- };
-
- window.addEventListener('beforeunload', listenToChanges);
- return () => {
- isMounted.current = false;
- window.removeEventListener('beforeunload', listenToChanges);
- };
- }, []);
-
const imageFormatOptions = useMemo((): SegmentedControlItem[] => {
if (renderMode === 'still') {
return [
diff --git a/packages/cli/src/event-source.ts b/packages/cli/src/event-source.ts
index 0789b8bcf8..bf1c0628f5 100644
--- a/packages/cli/src/event-source.ts
+++ b/packages/cli/src/event-source.ts
@@ -1,7 +1,4 @@
-import {
- notificationCenter,
- sendErrorNotification,
-} from './editor/components/Notifications/NotificationCenter';
+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';
@@ -35,17 +32,7 @@ export const openEventSource = () => {
newEvent.type === 'new-input-props' ||
newEvent.type === 'new-env-variables'
) {
- if (window.remotion_unsavedProps) {
- notificationCenter.current?.addNotification({
- id: new Date().toString(),
- content:
- 'There are unsaved changes to the props. Do you want to leave?',
- created: new Date().getMilliseconds(),
- duration: 1,
- });
- } else {
- window.location.reload();
- }
+ window.location.reload();
}
if (newEvent.type === 'init') {