Skip to content

🎥 Make videos programmatically with React

warn about duplicate environment variables

Jonny Burger310491479d88
diff --git a/packages/cli/src/editor/components/RenderModal/EnvInput.tsx b/packages/cli/src/editor/components/RenderModal/EnvInput.tsx
index d851d9a5e9..0bfbabe2ce 100644
--- a/packages/cli/src/editor/components/RenderModal/EnvInput.tsx
+++ b/packages/cli/src/editor/components/RenderModal/EnvInput.tsx
@@ -1,6 +1,7 @@
import React, {useCallback} from 'react';
import {Row, Spacing} from '../layout';
import {RemotionInput} from '../NewComposition/RemInput';
+import {ValidationMessage} from '../NewComposition/ValidationMessage';
import {InlineEyeButton} from './InlineEyeIcon';
import {InlineRemoveButton} from './InlineRemoveButton';
import {optionRow} from './layout';
@@ -10,6 +11,11 @@ const input: React.CSSProperties = {
width: '100%',
};
+const validationStyle = {
+ paddingLeft: optionRow.paddingLeft,
+ paddingRight: optionRow.paddingRight,
+};
+
export const EnvInput: React.FC<{
onEnvKeyChange: (index: number, newValue: string) => void;
onEnvValChange: (index: number, newValue: string) => void;
@@ -18,6 +24,7 @@ export const EnvInput: React.FC<{
onDelete: (index: number) => void;
index: number;
autoFocus: boolean;
+ isDuplicate: boolean;
}> = ({
onEnvKeyChange,
onEnvValChange,
@@ -26,6 +33,7 @@ export const EnvInput: React.FC<{
onDelete,
index,
autoFocus,
+ isDuplicate,
}) => {
const [showInPlainText, setShowInPlainText] = React.useState(false);
@@ -51,29 +59,51 @@ export const EnvInput: React.FC<{
[index, onEnvValChange]
);
+ const isNodeEnvKey = envKey.trim() === 'NODE_ENV';
+
return (
- <Row align="center" style={optionRow}>
- <RemotionInput
- status="ok"
- type="text"
- placeholder="Key"
- style={input}
- value={envKey}
- autoFocus={autoFocus}
- onChange={handleKeyChange}
- />
- <Spacing x={1} />
- <RemotionInput
- status="ok"
- placeholder="Value"
- type={showInPlainText ? 'text' : 'password'}
- style={input}
- value={envVal}
- onChange={handleValueChange}
- />
- <Spacing x={1.5} />
- <InlineEyeButton enabled={!showInPlainText} onClick={togglePlainText} />
- <InlineRemoveButton onClick={handleDelete} />
- </Row>
+ <>
+ <Row align="center" style={optionRow}>
+ <RemotionInput
+ status={isNodeEnvKey || isDuplicate ? 'warning' : 'ok'}
+ type="text"
+ placeholder="Key"
+ style={input}
+ value={envKey}
+ autoFocus={autoFocus}
+ onChange={handleKeyChange}
+ />
+ <Spacing x={1} />
+ <RemotionInput
+ status="ok"
+ placeholder="Value"
+ type={showInPlainText ? 'text' : 'password'}
+ style={input}
+ value={envVal}
+ onChange={handleValueChange}
+ />
+ <Spacing x={1.5} />
+ <InlineEyeButton enabled={!showInPlainText} onClick={togglePlainText} />
+ <InlineRemoveButton onClick={handleDelete} />
+ </Row>
+ {isNodeEnvKey ? (
+ <div style={validationStyle}>
+ <ValidationMessage
+ align="flex-start"
+ type="warning"
+ message="NODE_ENV will be overwritten by Remotion during the render process."
+ />
+ </div>
+ ) : null}
+ {isDuplicate ? (
+ <div style={validationStyle}>
+ <ValidationMessage
+ align="flex-start"
+ type="warning"
+ message={`${envKey.toUpperCase()} is already defined.`}
+ />
+ </div>
+ ) : null}
+ </>
);
};
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalEnvironmentVariables.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalEnvironmentVariables.tsx
index ff23096c09..b7e1b45151 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModalEnvironmentVariables.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModalEnvironmentVariables.tsx
@@ -20,8 +20,6 @@ const button: React.CSSProperties = {
};
// TODO: should warn if XOR key XOR value is empty
-// TODO: Should warn if trying to set the same key twice
-// TODO: Should warn if trying to set NODE_ENV
export const RenderModalEnvironmentVariables: React.FC<{
envVariables: [string, string][];
setEnvVariables: React.Dispatch<React.SetStateAction<[string, string][]>>;
@@ -59,10 +57,19 @@ export const RenderModalEnvironmentVariables: React.FC<{
setEnvVariables((oldEnv) => [...oldEnv, ['', '']]);
}, [setEnvVariables]);
+ const usedKeys: string[] = [];
return (
<div style={container}>
<strong style={title}>Environment variables</strong>
{envVariables.map((env, i) => {
+ let isDuplicate = false;
+
+ if (usedKeys.includes(env[0].toUpperCase())) {
+ isDuplicate = true;
+ }
+
+ usedKeys.push(env[0].toUpperCase());
+
return (
<EnvInput
// eslint-disable-next-line react/no-array-index-key
@@ -73,6 +80,7 @@ export const RenderModalEnvironmentVariables: React.FC<{
envVal={env[1]}
onDelete={onDelete}
index={i}
+ isDuplicate={isDuplicate}
autoFocus={i === envVariables.length - 1 && env[0] === ''}
/>
);
diff --git a/packages/cli/src/editor/helpers/convert-env-variables.ts b/packages/cli/src/editor/helpers/convert-env-variables.ts
index ede600ec98..145ee7e559 100644
--- a/packages/cli/src/editor/helpers/convert-env-variables.ts
+++ b/packages/cli/src/editor/helpers/convert-env-variables.ts
@@ -2,7 +2,7 @@ export const envVariablesObjectToArray = (
envVariables: Record<string, string>
): [string, string][] => {
return Object.entries(envVariables).map(([key, one]) => [
- key.trim(),
+ key.trim().toUpperCase(),
one.trim(),
]);
};
@@ -14,7 +14,7 @@ export const envVariablesArrayToObject = (
.map(([key, val]) => [key.trim(), val.trim()])
.filter(([key, val]) => key && val)
.reduce((acc, [key, value]) => {
- acc[key] = value;
+ acc[key.toUpperCase()] = value;
return acc;
}, {} as Record<string, string>);
};