Skip to content

🎥 Make videos programmatically with React

Reuse Studio modal for Browser Studio experimental notice

Igor Samokhovets967a2ce79d63
diff --git a/packages/browser-studio/src/BrowserStudio.tsx b/packages/browser-studio/src/BrowserStudio.tsx
index 6a2c424d38..cfec5f1e4e 100644
--- a/packages/browser-studio/src/BrowserStudio.tsx
+++ b/packages/browser-studio/src/BrowserStudio.tsx
@@ -162,6 +162,7 @@ export const BrowserStudio: React.FC<BrowserStudioProps> = ({
onCompileStateChange,
onProjectChange,
remotionPackageSource,
+ showExperimentalNotice = false,
}) => {
const [state, setState] = useState<CompileState>(makeInitialState);
const [iframeHtml, setIframeHtml] = useState<string | null>(null);
@@ -817,6 +818,8 @@ export const BrowserStudio: React.FC<BrowserStudioProps> = ({
(contentWindow as BrowserStudioContentWindow).remotion_browserStudioHmr =
hmrAssetManager.bridge;
contentWindow.remotion_browserStudio = browserStudioOperations;
+ contentWindow.remotion_showBrowserStudioExperimentalNotice =
+ showExperimentalNotice;
contentDocument.write(iframeHtml);
contentDocument.close();
@@ -826,6 +829,8 @@ export const BrowserStudio: React.FC<BrowserStudioProps> = ({
activeContentWindow as BrowserStudioContentWindow
).remotion_browserStudioHmr = hmrAssetManager.bridge;
activeContentWindow.remotion_browserStudio = browserStudioOperations;
+ activeContentWindow.remotion_showBrowserStudioExperimentalNotice =
+ showExperimentalNotice;
activeContentWindow.dispatchEvent(
new Event(BROWSER_STUDIO_OPERATIONS_READY_EVENT),
);
@@ -836,6 +841,7 @@ export const BrowserStudio: React.FC<BrowserStudioProps> = ({
iframeHtml,
iframeLoaded,
iframeSrc,
+ showExperimentalNotice,
]);
return (
diff --git a/packages/browser-studio/src/types.ts b/packages/browser-studio/src/types.ts
index e090d53a3c..634a27f175 100644
--- a/packages/browser-studio/src/types.ts
+++ b/packages/browser-studio/src/types.ts
@@ -69,6 +69,7 @@ export type BrowserStudioProps = {
sourceOrigin: string | null;
} | null;
iframeSrc?: string;
+ showExperimentalNotice?: boolean;
remotionPackageSource?: BrowserStudioRemotionPackageSource;
dependencyResolver?: BrowserStudioDependencyResolver;
onCompileStateChange?: (state: CompileState) => void;
diff --git a/packages/docs/standalone/experimental-new/index.tsx b/packages/docs/standalone/experimental-new/index.tsx
index d6a8ea90ee..0d60b8c6b7 100644
--- a/packages/docs/standalone/experimental-new/index.tsx
+++ b/packages/docs/standalone/experimental-new/index.tsx
@@ -6,14 +6,11 @@ import {
type VirtualProject,
} from '@remotion/browser-studio';
import {StudioProtocolInternals} from '@remotion/studio-protocol';
-import React, {useEffect, useRef, useState} from 'react';
+import React, {useEffect, useState} from 'react';
import {createRoot} from 'react-dom/client';
declare const __BROWSER_STUDIO_WORKSPACE_COMMIT__: string;
-const experimentalNoticeStorageKey =
- 'remotion-browser-studio-experimental-notice-acknowledged';
-
const page: React.CSSProperties = {
backgroundColor: '#111111',
color: '#ffffff',
@@ -120,33 +117,9 @@ const getInitialElementState = (): InitialElementState => {
const BrowserStudioContent: React.FC = () => {
const [initialElementState] = useState(getInitialElementState);
const [projectState, setProjectState] = useState(getInitialProjectState);
- const [noticeAcknowledged, setNoticeAcknowledged] = useState(() => {
- try {
- return (
- window.localStorage.getItem(experimentalNoticeStorageKey) === 'true'
- );
- } catch {
- return false;
- }
- });
- const [noticeKeyboardNavigation, setNoticeKeyboardNavigation] =
- useState(false);
- const noticeRef = useRef<HTMLDialogElement>(null);
- const noticeButtonRef = useRef<HTMLButtonElement>(null);
const loadingRepoUrl =
projectState.type === 'loading' ? projectState.repoUrl : null;
- useEffect(() => {
- const dialog = noticeRef.current;
- if (!dialog || noticeAcknowledged) {
- return;
- }
-
- dialog.showModal();
- noticeButtonRef.current?.focus();
- return () => dialog.close();
- }, [noticeAcknowledged]);
-
useEffect(() => {
if (initialElementState.type === 'none') {
return;
@@ -196,128 +169,6 @@ const BrowserStudioContent: React.FC = () => {
return <div style={fallback}>Invalid Browser Studio payload.</div>;
}
- if (!noticeAcknowledged) {
- return (
- <div style={{...loadingBackdrop, boxSizing: 'border-box'}}>
- <style>{`
- .experimental-notice.css-reset,
- .experimental-notice.css-reset * {
- font-size: 16px;
- line-height: 1.5;
- color: white;
- font-family: Arial, Helvetica, sans-serif;
- background: transparent;
- box-sizing: border-box;
- }
- .experimental-notice .experimental-notice-copy,
- .experimental-notice .experimental-notice-copy * {
- font-size: 14px;
- color: #a6a7a9;
- }
- .experimental-notice-control {
- cursor: default;
- }
- @media (hover: hover) {
- .experimental-notice .experimental-notice-link:hover {
- color: white;
- }
- }
- .experimental-notice-control:focus {
- outline: none;
- box-shadow: none;
- }
- .experimental-notice[data-keyboard-navigation="true"] .experimental-notice-control:focus-visible {
- box-shadow: inset 1px 1px #555, inset -1px -1px #555,
- inset 1px -1px #555, inset -1px 1px #555;
- }
- `}</style>
- <dialog
- ref={noticeRef}
- className="experimental-notice css-reset"
- aria-labelledby="experimental-notice-title"
- aria-describedby="experimental-notice-description"
- data-keyboard-navigation={noticeKeyboardNavigation}
- onCancel={(event) => event.preventDefault()}
- onKeyDown={(event) => {
- if (event.key === 'Tab') {
- setNoticeKeyboardNavigation(true);
- }
- }}
- style={{
- ...loadingDialog,
- backgroundColor: 'rgb(31, 36, 40)',
- maxHeight: 'calc(100dvh - 48px)',
- width: 'calc(100vw - 48px)',
- }}
- >
- <h1
- id="experimental-notice-title"
- style={{fontSize: 18, fontWeight: 600, margin: 0}}
- >
- Browser Studio is experimental
- </h1>
- <div
- id="experimental-notice-description"
- className="experimental-notice-copy"
- >
- <p>
- This is a playground for trying Remotion’s editing features.
- Projects aren’t saved between visits, and AI interaction isn’t
- available here as it is in the{' '}
- <a
- className="experimental-notice-control experimental-notice-link"
- href="https://www.remotion.dev/docs/studio/studio"
- rel="noopener noreferrer"
- target="_blank"
- >
- regular Remotion Studio
- </a>
- .
- </p>
- <p>
- To keep working on your project, use{' '}
- <strong>Download project</strong> and continue locally.
- </p>
- </div>
- <div
- style={{display: 'flex', justifyContent: 'flex-end', marginTop: 20}}
- >
- <button
- ref={noticeButtonRef}
- className="experimental-notice-control"
- onClick={() => {
- try {
- window.localStorage.setItem(
- experimentalNoticeStorageKey,
- 'true',
- );
- } catch {
- // Still allow experimenting when browser storage is unavailable.
- }
-
- setNoticeAcknowledged(true);
- }}
- style={{
- appearance: 'none',
- backgroundColor: '#0b84f3',
- border: 0,
- borderRadius: 6,
- color: 'white',
- fontSize: 14,
- margin: 0,
- minWidth: 64,
- padding: 10,
- }}
- type="button"
- >
- OK
- </button>
- </div>
- </dialog>
- </div>
- );
- }
-
if (projectState.type !== 'ready') {
let progress: number | null = null;
if (
@@ -415,6 +266,7 @@ const BrowserStudioContent: React.FC = () => {
}
project={projectState.project}
readOnly={false}
+ showExperimentalNotice
remotionPackageSource={{
baseUrl: new URL(
`/__remotion_browser_studio_workspace__/commits/${__BROWSER_STUDIO_WORKSPACE_COMMIT__}/`,
diff --git a/packages/studio-shared/src/browser-studio-operations.ts b/packages/studio-shared/src/browser-studio-operations.ts
index b493d91094..68e5fef24e 100644
--- a/packages/studio-shared/src/browser-studio-operations.ts
+++ b/packages/studio-shared/src/browser-studio-operations.ts
@@ -269,5 +269,6 @@ export type BrowserStudioOperations = {
declare global {
interface Window {
remotion_browserStudio?: BrowserStudioOperations;
+ remotion_showBrowserStudioExperimentalNotice: boolean | null;
}
}
diff --git a/packages/studio/src/components/BrowserStudioExperimentalNotice.tsx b/packages/studio/src/components/BrowserStudioExperimentalNotice.tsx
new file mode 100644
index 0000000000..b900bce329
--- /dev/null
+++ b/packages/studio/src/components/BrowserStudioExperimentalNotice.tsx
@@ -0,0 +1,130 @@
+import React, {useCallback, useContext, useState} from 'react';
+import {ShortcutHint} from '../error-overlay/remotion-overlay/ShortcutHint';
+import {LIGHT_TEXT, TRANSPARENT, WHITE} from '../helpers/colors';
+import {
+ FOCUS_VISIBLE_ONLY_CLASS_NAME,
+ HOVERABLE_CLASS_NAME,
+ hoverableStyle,
+} from '../helpers/hoverable';
+import {SetSelectedModalContext} from '../state/modals';
+import {Flex, Row} from './layout';
+import {ModalButton} from './ModalButton';
+import {getMaxModalWidth, ModalContainer} from './ModalContainer';
+import {ModalFooterContainer} from './ModalFooter';
+import {ModalHeader} from './ModalHeader';
+
+export const experimentalNoticeStorageKey =
+ 'remotion-browser-studio-experimental-notice-acknowledged';
+
+const panelStyle: React.CSSProperties = {
+ borderRadius: 6,
+ display: 'flex',
+ flexDirection: 'column',
+ maxHeight: 'calc(100dvh - 40px)',
+ minWidth: 0,
+ overflow: 'hidden',
+ width: getMaxModalWidth(520),
+};
+
+const bodyTextStyle: React.CSSProperties = {
+ color: LIGHT_TEXT,
+ fontFamily: 'Arial, Helvetica, sans-serif',
+ fontSize: 14,
+ lineHeight: 1.5,
+};
+
+const linkStyle: React.CSSProperties = {
+ fontFamily: bodyTextStyle.fontFamily,
+ fontSize: bodyTextStyle.fontSize,
+ lineHeight: bodyTextStyle.lineHeight,
+ ...hoverableStyle({
+ idleBackground: TRANSPARENT,
+ hoverBackground: TRANSPARENT,
+ idleColor: LIGHT_TEXT,
+ hoverColor: WHITE,
+ }),
+ cursor: 'default',
+};
+
+const buttonTextStyle: React.CSSProperties = {
+ color: WHITE,
+ fontFamily: 'Arial, Helvetica, sans-serif',
+ fontSize: 14,
+ lineHeight: 1.5,
+};
+
+export const BrowserStudioExperimentalNotice: React.FC = () => {
+ const {setSelectedModal} = useContext(SetSelectedModalContext);
+ const [keyboardNavigation, setKeyboardNavigation] = useState(false);
+
+ const onClose = useCallback(() => {
+ try {
+ window.localStorage.setItem(experimentalNoticeStorageKey, 'true');
+ } catch {
+ // Still allow experimenting when browser storage is unavailable.
+ }
+
+ setSelectedModal(null);
+ }, [setSelectedModal]);
+
+ return (
+ <div
+ className="__remotion-browser-studio-experimental-notice"
+ data-keyboard-navigation={keyboardNavigation}
+ onKeyDown={(event) => {
+ if (event.key === 'Tab') {
+ setKeyboardNavigation(true);
+ }
+ }}
+ >
+ <style>{`
+ .__remotion-browser-studio-experimental-notice[data-keyboard-navigation="false"] .${FOCUS_VISIBLE_ONLY_CLASS_NAME}:focus {
+ box-shadow: none;
+ }
+ `}</style>
+ <ModalContainer
+ ariaLabel="Browser Studio is experimental"
+ onEscape={onClose}
+ onOutsideClick={onClose}
+ panelStyle={panelStyle}
+ >
+ <ModalHeader title="Browser Studio is experimental" onClose={onClose} />
+ <div style={{padding: 16, minHeight: 0, overflowY: 'auto'}}>
+ <p style={{...bodyTextStyle, margin: '0 0 12px'}}>
+ This is a playground for trying Remotion’s editing features.
+ Projects aren’t saved between visits, and AI interaction isn’t
+ available here as it is in the{' '}
+ <a
+ className={`${HOVERABLE_CLASS_NAME} ${FOCUS_VISIBLE_ONLY_CLASS_NAME}`}
+ href="https://www.remotion.dev/docs/studio"
+ rel="noopener noreferrer"
+ style={linkStyle}
+ target="_blank"
+ >
+ regular Remotion Studio
+ </a>
+ .
+ </p>
+ <p style={{...bodyTextStyle, margin: 0}}>
+ To keep working on your project, use{' '}
+ <strong style={bodyTextStyle}>Download project</strong> and continue
+ locally.
+ </p>
+ </div>
+ <ModalFooterContainer style={{minWidth: 0, flex: 'none'}}>
+ <Row align="center">
+ <Flex />
+ <ModalButton
+ onClick={onClose}
+ autoFocus
+ buttonContainerStyle={buttonTextStyle}
+ >
+ OK
+ <ShortcutHint keyToPress="↵" cmdOrCtrl={false} />
+ </ModalButton>
+ </Row>
+ </ModalFooterContainer>
+ </ModalContainer>
+ </div>
+ );
+};
diff --git a/packages/studio/src/components/ElementInstallRequestHandler.tsx b/packages/studio/src/components/ElementInstallRequestHandler.tsx
index 4b277163ff..da7dc31e10 100644
--- a/packages/studio/src/components/ElementInstallRequestHandler.tsx
+++ b/packages/studio/src/components/ElementInstallRequestHandler.tsx
@@ -16,7 +16,7 @@ import {Internals} from 'remotion';
import {getBrowserStudioOperations} from '../helpers/browser-studio-operations';
import {StudioServerConnectionCtx} from '../helpers/client-id';
import {getMissingPackages} from '../helpers/install-required-package';
-import {SetSelectedModalContext} from '../state/modals';
+import {SelectedModalContext, SetSelectedModalContext} from '../state/modals';
import {callApi} from './call-api';
import {prepareElementInstall} from './element-install-api';
import {
@@ -34,6 +34,9 @@ export const ElementInstallRequestHandler: FC = () => {
);
const config = Internals.useUnsafeVideoConfig();
const {setSelectedModal} = useContext(SetSelectedModalContext);
+ const selectedModal = useContext(SelectedModalContext);
+ const showingExperimentalNotice =
+ selectedModal?.type === 'browser-studio-experimental-notice';
const {previewServerState, subscribeToEvent} = useContext(
StudioServerConnectionCtx,
);
@@ -251,7 +254,7 @@ export const ElementInstallRequestHandler: FC = () => {
}, [config]);
useEffect(() => {
- if (!canInstallElement) {
+ if (!canInstallElement || showingExperimentalNotice) {
return;
}
@@ -275,10 +278,19 @@ export const ElementInstallRequestHandler: FC = () => {
type: 'browser-studio-link',
},
});
- }, [canInstallElement, compositionFile, currentCompositionId]);
+ }, [
+ canInstallElement,
+ compositionFile,
+ currentCompositionId,
+ showingExperimentalNotice,
+ ]);
useEffect(() => {
- if (activeRequest !== null || pendingRequests.length === 0) {
+ if (
+ activeRequest !== null ||
+ pendingRequests.length === 0 ||
+ showingExperimentalNotice
+ ) {
return;
}
@@ -289,7 +301,7 @@ export const ElementInstallRequestHandler: FC = () => {
setActiveRequest(nextRequest);
setPendingRequests(remainingRequests);
- }, [activeRequest, pendingRequests]);
+ }, [activeRequest, pendingRequests, showingExperimentalNotice]);
const closeElementInstallDialog = useCallback(() => {
setSelectedModal((modal) =>
diff --git a/packages/studio/src/components/Modals.tsx b/packages/studio/src/components/Modals.tsx
index 67fe583529..249e64e3ec 100644
--- a/packages/studio/src/components/Modals.tsx
+++ b/packages/studio/src/components/Modals.tsx
@@ -9,6 +9,7 @@ import {getStudioAskAIEnabled} from '../helpers/studio-runtime-config';
import {SelectedModalContext, SetSelectedModalContext} from '../state/modals';
import {AskAiModal} from './AskAiModal';
import {AssetSelectorModal} from './AssetSelectorModal';
+import {BrowserStudioExperimentalNotice} from './BrowserStudioExperimentalNotice';
import {callApi} from './call-api';
import {ConfirmationDialog, useConfirmationDialog} from './ConfirmationDialog';
import {EffectPickerModal} from './EffectPickerModal';
@@ -250,6 +251,9 @@ export const Modals: React.FC<{
return (
<>
+ {modalContextType?.type === 'browser-studio-experimental-notice' ? (
+ <BrowserStudioExperimentalNotice />
+ ) : null}
{modalContextType && modalContextType.type === 'new-comp' && (
<NewComposition
folderName={modalContextType.folderName}
diff --git a/packages/studio/src/components/ModalsProvider.tsx b/packages/studio/src/components/ModalsProvider.tsx
index c4eb4a2534..eb389de35d 100644
--- a/packages/studio/src/components/ModalsProvider.tsx
+++ b/packages/studio/src/components/ModalsProvider.tsx
@@ -1,11 +1,32 @@
import React, {useMemo, useState} from 'react';
+import {getBrowserStudioOperations} from '../helpers/browser-studio-operations';
import type {ModalState, SetSelectedModalContextType} from '../state/modals';
import {SelectedModalContext, SetSelectedModalContext} from '../state/modals';
+import {experimentalNoticeStorageKey} from './BrowserStudioExperimentalNotice';
export const ModalsProvider: React.FC<{
readonly children: React.ReactNode;
}> = ({children}) => {
- const [selectedModal, setSelectedModal] = useState<ModalState | null>(null);
+ const [selectedModal, setSelectedModal] = useState<ModalState | null>(() => {
+ if (
+ getBrowserStudioOperations() === null ||
+ !window.remotion_showBrowserStudioExperimentalNotice
+ ) {
+ return null;
+ }
+
+ try {
+ if (
+ window.localStorage.getItem(experimentalNoticeStorageKey) === 'true'
+ ) {
+ return null;
+ }
+ } catch {
+ // Show the notice even when browser storage is unavailable.
+ }
+
+ return {type: 'browser-studio-experimental-notice'};
+ });
const setSelectedModalContext = useMemo((): SetSelectedModalContextType => {
return {
diff --git a/packages/studio/src/state/modals.ts b/packages/studio/src/state/modals.ts
index 5fb7c8eddb..8ac9ce2047 100644
--- a/packages/studio/src/state/modals.ts
+++ b/packages/studio/src/state/modals.ts
@@ -322,6 +322,9 @@ export type ModalState =
};
wrapper: NodeWrapper;
}
+ | {
+ type: 'browser-studio-experimental-notice';
+ }
| {
type: 'html-in-canvas-unavailable';
action: 'effects' | 'motion-blur';