Skip to content

The Open Standard for Generative UI

Fix ThemeProvider crash in environments without process global (#266)

Ankit Dasd580fc1aa5e0
diff --git a/.gitignore b/.gitignore
index 5847c142a..83468ded9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,9 @@ typings
# Logs
*storybook.log
+
+# scripts and tools
+clean-install.sh
+lint-fix.sh
+
+draft/
\ No newline at end of file
diff --git a/packages/react-ui/src/components/ThemeProvider/ThemeProvider.tsx b/packages/react-ui/src/components/ThemeProvider/ThemeProvider.tsx
index a4116b379..f8588beb3 100644
--- a/packages/react-ui/src/components/ThemeProvider/ThemeProvider.tsx
+++ b/packages/react-ui/src/components/ThemeProvider/ThemeProvider.tsx
@@ -168,7 +168,7 @@ export const ThemeProvider = ({
// ---------------------------------------------------------------------------
// Dev-mode warnings
// ---------------------------------------------------------------------------
- if (process.env["NODE_ENV"] !== "production") {
+ if (typeof process !== "undefined" && process.env?.["NODE_ENV"] !== "production") {
if (deprecatedTheme !== undefined && lightTheme !== undefined) {
warnOnce(
"theme+lightTheme",
diff --git a/packages/react-ui/src/components/ThemeProvider/utils.ts b/packages/react-ui/src/components/ThemeProvider/utils.ts
index 414428381..4dd47ca83 100644
--- a/packages/react-ui/src/components/ThemeProvider/utils.ts
+++ b/packages/react-ui/src/components/ThemeProvider/utils.ts
@@ -66,7 +66,7 @@ const _warnedKeys = new Set<string>();
* @returns The same `theme` object, unmodified.
*/
export function createTheme(theme: Theme): Theme {
- if (process.env["NODE_ENV"] !== "production") {
+ if (typeof process !== "undefined" && process.env?.["NODE_ENV"] !== "production") {
const knownKeys = Object.keys(defaultLightTheme);
for (const key of Object.keys(theme)) {
if (knownKeys.includes(key) || _warnedKeys.has(key)) continue;