🎥 Make videos programmatically with React
@remotion/studio: Refine Studio restart flow
Jonny Burger514ecaeb34e4
diff --git a/packages/cli/src/restart-studio-process.ts b/packages/cli/src/restart-studio-process.tsindex 3094e9bca1..54680e4ebb 100644--- a/packages/cli/src/restart-studio-process.ts+++ b/packages/cli/src/restart-studio-process.ts@@ -1,5 +1,34 @@import {spawn} from 'node:child_process';+export const getRestartStudioProcessArgs = ({+ argv,+ execArgv,+ port,+}: {+ argv: string[];+ execArgv: string[];+ port: number;+}) => {+ const args = argv.slice(1);+ const argsWithoutPort: string[] = [];++ for (let index = 0; index < args.length; index++) {+ const arg = args[index]!;+ if (arg === '--port') {+ index++;+ continue;+ }++ if (arg.startsWith('--port=')) {+ continue;+ }++ argsWithoutPort.push(arg);+ }++ return [...execArgv, ...argsWithoutPort, `--port=${port}`];+};+export const restartStudioProcess = ({command,args,diff --git a/packages/cli/src/studio.ts b/packages/cli/src/studio.tsindex 8abc2e77bb..6ac7476eb4 100644--- a/packages/cli/src/studio.ts+++ b/packages/cli/src/studio.ts@@ -29,7 +29,10 @@ import {getRenderQueue,removeJob,} from './render-queue/queue';-import {restartStudioProcess} from './restart-studio-process';+import {+ getRestartStudioProcessArgs,+ restartStudioProcess,+} from './restart-studio-process';const {binariesDirectoryOption,@@ -353,6 +356,10 @@ export const studioCommand = async (await restartStudioProcess({command: process.execPath,- args: [...process.execArgv, ...process.argv.slice(1)],+ args: getRestartStudioProcessArgs({+ argv: process.argv,+ execArgv: process.execArgv,+ port: result.port,+ }),});};diff --git a/packages/cli/src/test/restart-studio-process.test.ts b/packages/cli/src/test/restart-studio-process.test.tsindex 27ffcec891..ab672884d4 100644--- a/packages/cli/src/test/restart-studio-process.test.ts+++ b/packages/cli/src/test/restart-studio-process.test.ts@@ -1,5 +1,33 @@import {expect, test} from 'bun:test';-import {restartStudioProcess} from '../restart-studio-process';+import {+ getRestartStudioProcessArgs,+ restartStudioProcess,+} from '../restart-studio-process';++test('restarts Studio on the same port', () => {+ expect(+ getRestartStudioProcessArgs({+ argv: [+ '/usr/local/bin/node',+ '/project/remotion-cli.js',+ 'studio',+ 'index.ts',+ '--port',+ '3000',+ '--no-open',+ ],+ execArgv: ['--trace-warnings'],+ port: 3002,+ }),+ ).toEqual([+ '--trace-warnings',+ '/project/remotion-cli.js',+ 'studio',+ 'index.ts',+ '--no-open',+ '--port=3002',+ ]);+});test('waits for the restarted process to exit', async () => {let exited = false;diff --git a/packages/docs/docs/studio/restart-studio.mdx b/packages/docs/docs/studio/restart-studio.mdxindex 670d6bace0..38b29bd922 100644--- a/packages/docs/docs/studio/restart-studio.mdx+++ b/packages/docs/docs/studio/restart-studio.mdx@@ -39,7 +39,7 @@ Otherwise, the function will throw.## Return value-Returns a promise that resolves to an empty object when the server acknowledges the restart request. The browser temporarily disconnects while Studio restarts.+Returns a promise that resolves to an empty object when the server acknowledges the restart request. Studio launches a fresh CLI process on the same port, so package upgrades take effect after restarting. The browser temporarily disconnects while Studio restarts.## See alsodiff --git a/packages/studio-server/src/start-studio.ts b/packages/studio-server/src/start-studio.tsindex c6b6e34b5d..89ed85824b 100644--- a/packages/studio-server/src/start-studio.ts+++ b/packages/studio-server/src/start-studio.ts@@ -35,7 +35,7 @@ import {printServerReadyComment, setServerReadyComment} from './server-ready';import {watchRootFile} from './watch-root-file';export type StartStudioResult =- | {type: 'restarted'}+ | {type: 'restarted'; port: number}| {type: 'already-running'}| {type: 'shutdown'};@@ -271,5 +271,5 @@ export const startStudio = async ({RenderInternals.chalk.blue('Restarting server...'),);- return {type: 'restarted'};+ return {type: 'restarted', port};};diff --git a/packages/studio/src/api/restart-studio.ts b/packages/studio/src/api/restart-studio.tsindex bc114a5f19..88784548a1 100644--- a/packages/studio/src/api/restart-studio.ts+++ b/packages/studio/src/api/restart-studio.ts@@ -1,5 +1,5 @@/**- * @description Restarts the Remotion Studio.+ * @description Restarts the Remotion Studio process.* @see [Documentation](https://www.remotion.dev/docs/studio/restart-studio)*/diff --git a/packages/studio/src/components/SettingsModalFooter.tsx b/packages/studio/src/components/SettingsModalFooter.tsxindex eec63abdcc..2c5efb770c 100644--- a/packages/studio/src/components/SettingsModalFooter.tsx+++ b/packages/studio/src/components/SettingsModalFooter.tsx@@ -5,6 +5,7 @@ import {BLUE, CURRENT_COLOR, LIGHT_TEXT} from '../helpers/colors';import {InspectorOpenInEditor} from './InspectorOpenInEditor';import {InspectorQuickAction} from './InspectorPanel/common';import {Spacing} from './layout';+import {ModalButton} from './ModalButton';import {ModalFooterContainer} from './ModalFooter';import {showNotification} from './Notifications/NotificationCenter';@@ -15,6 +16,7 @@ const footer: React.CSSProperties = {const footerRow: React.CSSProperties = {alignItems: 'center',display: 'flex',+ height: 28,justifyContent: 'space-between',};@@ -75,24 +77,32 @@ export const SettingsModalFooter: React.FC<{<ModalFooterContainer style={footer}><div style={footerRow}><div style={configFileHint}>- Changes save to- <Spacing x={0.5} />- <InspectorOpenInEditor- locationType={null}- location={configFileLocation}- label={<strong style={configFileName}>remotion.config.ts</strong>}- showTooltips={false}- />+ {restartRequired ? (+ 'Restart the server to apply changes'+ ) : (+ <>+ Changes save to+ <Spacing x={0.5} />+ <InspectorOpenInEditor+ locationType={null}+ location={configFileLocation}+ label={+ <strong style={configFileName}>remotion.config.ts</strong>+ }+ showTooltips={false}+ />+ </>+ )}</div>{restartRequired ? (- <InspectorQuickAction+ <ModalButtondisabled={restarting}onClick={restart}- style={{flex: 'none', width: 'fit-content'}}+ size="compact"title="Restart Studio to apply config file changes">{restarting ? 'Restarting...' : 'Restart Studio'}- </InspectorQuickAction>+ </ModalButton>) : showLicenseFaq ? (<InspectorQuickActiondisabled={false}