Skip to content

🎥 Make videos programmatically with React

`remotion`: Fix bug where React was included in `remotion/no-react` entry point

JonnyBurgerd91b680f6a86
diff --git a/packages/core/bundle.ts b/packages/core/bundle.ts
index 0be455d6e9..d7f02386d2 100644
--- a/packages/core/bundle.ts
+++ b/packages/core/bundle.ts
@@ -39,7 +39,13 @@ const noReactOutput = await build({
external: ['remotion', 'react', 'react-dom'],
});
const [noReactFile] = noReactOutput.outputs;
-await Bun.write('dist/esm/no-react.mjs', await noReactFile.text());
+const noReactText = await noReactFile.text();
+
+if (noReactText.includes('createContext')) {
+ throw new Error('remotion/no-react.mjs should not import React');
+}
+
+await Bun.write('dist/esm/no-react.mjs', noReactText);
export {};
diff --git a/packages/core/src/delay-render.ts b/packages/core/src/delay-render.ts
index 31b638ebe8..0ebbaacc81 100644
--- a/packages/core/src/delay-render.ts
+++ b/packages/core/src/delay-render.ts
@@ -1,7 +1,7 @@
import {cancelRender} from './cancel-render.js';
-import type {RemotionEnvironment} from './get-remotion-environment.js';
import {getRemotionEnvironment} from './get-remotion-environment.js';
import {Log} from './log.js';
+import type {RemotionEnvironment} from './remotion-environment-context.js';
import {truthy} from './truthy.js';
if (typeof window !== 'undefined') {
diff --git a/packages/core/src/get-remotion-environment.ts b/packages/core/src/get-remotion-environment.ts
index 6f7d2ddeab..202ec2c2cd 100644
--- a/packages/core/src/get-remotion-environment.ts
+++ b/packages/core/src/get-remotion-environment.ts
@@ -1,12 +1,4 @@
-import React from 'react';
-
-export type RemotionEnvironment = {
- isStudio: boolean;
- isRendering: boolean;
- isClientSideRendering: boolean;
- isPlayer: boolean;
- isReadOnlyStudio: boolean;
-};
+import type {RemotionEnvironment} from './remotion-environment-context';
// Avoid VITE obfuscation
function getNodeEnvString() {
@@ -44,6 +36,3 @@ export const getRemotionEnvironment = (): RemotionEnvironment => {
isClientSideRendering: false,
};
};
-
-export const RemotionEnvironmentContext =
- React.createContext<RemotionEnvironment | null>(null);
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index 9f4b6987d4..2a4b4fd293 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -41,11 +41,7 @@ import {
getPreviewDomElement,
REMOTION_STUDIO_CONTAINER_ELEMENT,
} from './get-preview-dom-element.js';
-import type {RemotionEnvironment} from './get-remotion-environment.js';
-import {
- getRemotionEnvironment,
- RemotionEnvironmentContext,
-} from './get-remotion-environment.js';
+import {getRemotionEnvironment} from './get-remotion-environment.js';
import type {SerializedJSONWithCustomFields} from './input-props-serialization.js';
import {IsPlayerContextProvider, useIsPlayer} from './is-player.js';
import type {LoggingContextValue} from './log-level-context.js';
@@ -57,6 +53,8 @@ import {portalNode} from './portal-node.js';
import {PrefetchProvider} from './prefetch-state.js';
import {usePreload} from './prefetch.js';
import {getRoot, waitForRoot} from './register-root.js';
+import type {RemotionEnvironment} from './remotion-environment-context.js';
+import {RemotionEnvironmentContext} from './remotion-environment-context.js';
import {RemotionRoot} from './RemotionRoot.js';
import {RenderAssetManager} from './RenderAssetManager.js';
import {resolveVideoConfig} from './resolve-video-config.js';
diff --git a/packages/core/src/remotion-environment-context.ts b/packages/core/src/remotion-environment-context.ts
new file mode 100644
index 0000000000..f93dfa9fb6
--- /dev/null
+++ b/packages/core/src/remotion-environment-context.ts
@@ -0,0 +1,12 @@
+import React from 'react';
+
+export type RemotionEnvironment = {
+ isStudio: boolean;
+ isRendering: boolean;
+ isClientSideRendering: boolean;
+ isPlayer: boolean;
+ isReadOnlyStudio: boolean;
+};
+
+export const RemotionEnvironmentContext =
+ React.createContext<RemotionEnvironment | null>(null);
diff --git a/packages/core/src/use-remotion-environment.ts b/packages/core/src/use-remotion-environment.ts
index ff7f750630..88fdf7cf7d 100644
--- a/packages/core/src/use-remotion-environment.ts
+++ b/packages/core/src/use-remotion-environment.ts
@@ -1,9 +1,7 @@
import {useContext, useState} from 'react';
-import {
- getRemotionEnvironment,
- RemotionEnvironmentContext,
- type RemotionEnvironment,
-} from './get-remotion-environment';
+import {getRemotionEnvironment} from './get-remotion-environment';
+import type {RemotionEnvironment} from './remotion-environment-context';
+import {RemotionEnvironmentContext} from './remotion-environment-context';
/**
* @description A React hook that provides information about the current Remotion Environment. This is the preferred way to access environment information in React components as it will support future scoped contexts.