Skip to content

🎥 Make videos programmatically with React

Define the React Refresh event names in remotion instead of adding a studio-shared dependency to the browser bundler

JonnyBurgerea01eb5a2281
diff --git a/bun.lock b/bun.lock
index e4756e5961..b9cd369e7e 100644
--- a/bun.lock
+++ b/bun.lock
@@ -154,7 +154,6 @@
"name": "@remotion/browser-bundler",
"version": "4.0.529",
"dependencies": {
- "@remotion/studio-shared": "workspace:*",
"@rspack/browser": "2.1.1",
"react-refresh": "0.18.0",
"remotion": "workspace:*",
diff --git a/packages/browser-bundler/bundle.ts b/packages/browser-bundler/bundle.ts
index 1981f25000..d742748dc6 100644
--- a/packages/browser-bundler/bundle.ts
+++ b/packages/browser-bundler/bundle.ts
@@ -40,7 +40,6 @@ const output = await build({
target: 'browser',
define,
external: [
- '@remotion/studio-shared',
'@rspack/browser',
'react',
'react-dom',
diff --git a/packages/browser-bundler/package.json b/packages/browser-bundler/package.json
index 114f462774..3186c74c46 100644
--- a/packages/browser-bundler/package.json
+++ b/packages/browser-bundler/package.json
@@ -24,7 +24,6 @@
"url": "https://github.com/remotion-dev/remotion/issues"
},
"dependencies": {
- "@remotion/studio-shared": "workspace:*",
"@rspack/browser": "2.1.1",
"react-refresh": "0.18.0",
"remotion": "workspace:*"
diff --git a/packages/browser-bundler/src/create-browser-bundle-runtime.ts b/packages/browser-bundler/src/create-browser-bundle-runtime.ts
index b09d300346..afe7a55950 100644
--- a/packages/browser-bundler/src/create-browser-bundle-runtime.ts
+++ b/packages/browser-bundler/src/create-browser-bundle-runtime.ts
@@ -1,7 +1,3 @@
-import {
- REACT_REFRESH_FINISHED_EVENT,
- REACT_REFRESH_STARTED_EVENT,
-} from '@remotion/studio-shared';
import type {FC} from 'react';
import {Internals} from 'remotion';
import {createBrowserModuleScope} from './browser-module-scope';
@@ -191,9 +187,13 @@ export const createBrowserBundleRuntime = (): BrowserBundleRuntime => {
// Authoring UIs such as <Canvas> commit queued source-node remappings
// on the started event, in the same task as the refreshed tree.
- window.dispatchEvent(new Event(REACT_REFRESH_STARTED_EVENT));
+ window.dispatchEvent(
+ new Event(Internals.REACT_REFRESH_STARTED_EVENT),
+ );
if (refresh.performReactRefresh() !== null) {
- window.dispatchEvent(new Event(REACT_REFRESH_FINISHED_EVENT));
+ window.dispatchEvent(
+ new Event(Internals.REACT_REFRESH_FINISHED_EVENT),
+ );
}
}
diff --git a/packages/browser-bundler/tsconfig.json b/packages/browser-bundler/tsconfig.json
index 49b4e5c2c5..00f904424c 100644
--- a/packages/browser-bundler/tsconfig.json
+++ b/packages/browser-bundler/tsconfig.json
@@ -12,9 +12,5 @@
"emitDeclarationOnly": true
},
"include": ["src"],
- "references": [
- {"path": "../core"},
- {"path": "../player"},
- {"path": "../studio-shared"}
- ]
+ "references": [{"path": "../core"}, {"path": "../player"}]
}
diff --git a/packages/canvas/src/canvas.tsx b/packages/canvas/src/canvas.tsx
index ad9a056e0f..aa18d4de0f 100644
--- a/packages/canvas/src/canvas.tsx
+++ b/packages/canvas/src/canvas.tsx
@@ -1,6 +1,5 @@
import type {PlayerProps, PlayerRef} from '@remotion/player';
import {Player, PlayerInternals} from '@remotion/player';
-import {REACT_REFRESH_STARTED_EVENT} from '@remotion/studio-shared';
import type {RefObject} from 'react';
import React, {
forwardRef,
@@ -104,9 +103,9 @@ const CanvasFn = <
}
const commit = () => internals.commitQueuedSequenceNodePathRemappings();
- window.addEventListener(REACT_REFRESH_STARTED_EVENT, commit);
+ window.addEventListener(Internals.REACT_REFRESH_STARTED_EVENT, commit);
return () =>
- window.removeEventListener(REACT_REFRESH_STARTED_EVENT, commit);
+ window.removeEventListener(Internals.REACT_REFRESH_STARTED_EVENT, commit);
}, [internals]);
// React Refresh (used by Browser Studio) or React DevTools must have
// registered the renderer before this commit. Install before the commit hook
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index 5c2e8e59f8..8d1c05c949 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -138,6 +138,10 @@ import {portalNode, setPortalNodeCurrentScale} from './portal-node.js';
import {PrefetchProvider} from './prefetch-state.js';
import {usePreload} from './prefetch.js';
import {PremountContext} from './PremountContext.js';
+import {
+ REACT_REFRESH_FINISHED_EVENT,
+ REACT_REFRESH_STARTED_EVENT,
+} from './react-refresh-event.js';
import {getRoot, waitForRoot} from './register-root.js';
import type {RemotionEnvironment} from './remotion-environment-context.js';
import {RemotionEnvironmentContext} from './remotion-environment-context.js';
@@ -429,6 +433,8 @@ export const Internals = {
useTimelineSetFrameWithoutSeek,
isIosSafari,
WATCH_REMOTION_STATIC_FILES,
+ REACT_REFRESH_STARTED_EVENT,
+ REACT_REFRESH_FINISHED_EVENT,
addSequenceStackTraces,
useMediaStartsAt,
BufferingProvider,
diff --git a/packages/core/src/react-refresh-event.ts b/packages/core/src/react-refresh-event.ts
new file mode 100644
index 0000000000..384ee607ca
--- /dev/null
+++ b/packages/core/src/react-refresh-event.ts
@@ -0,0 +1,5 @@
+// Dispatched on `window` by the Fast Refresh integrations of the bundlers
+// around `performReactRefresh()`, so editors can synchronize state with the
+// refreshed tree.
+export const REACT_REFRESH_STARTED_EVENT = 'remotion-react-refresh-started';
+export const REACT_REFRESH_FINISHED_EVENT = 'remotion-react-refresh-finished';
diff --git a/packages/studio-shared/src/react-refresh-event.ts b/packages/studio-shared/src/react-refresh-event.ts
index 5d11c7a202..3db5f9d547 100644
--- a/packages/studio-shared/src/react-refresh-event.ts
+++ b/packages/studio-shared/src/react-refresh-event.ts
@@ -1,2 +1,4 @@
-export const REACT_REFRESH_STARTED_EVENT = 'remotion-react-refresh-started';
-export const REACT_REFRESH_FINISHED_EVENT = 'remotion-react-refresh-finished';
+import {Internals} from 'remotion';
+
+export const {REACT_REFRESH_STARTED_EVENT, REACT_REFRESH_FINISHED_EVENT} =
+ Internals;