diff --git a/src/createContainer.ts b/src/createContainer.ts index 46982df6..5617f763 100644 --- a/src/createContainer.ts +++ b/src/createContainer.ts @@ -16,6 +16,8 @@ import type { Context } from 'use-context-selector'; import { createTrackedSelector } from './createTrackedSelector.js'; +const hasGlobalProcess = typeof process === 'object'; + // eslint-disable-next-line @typescript-eslint/no-explicit-any type AnyFunction = (...args: any[]) => any; type Options = { @@ -69,7 +71,7 @@ export const createContainer = ( }; const useSelector = (selector: (state: State) => Selected) => { - if (typeof process === 'object' && process.env.NODE_ENV !== 'production') { + if (hasGlobalProcess && process.env.NODE_ENV !== 'production') { const selectorOrig = selector; selector = (state: State) => { if (state === undefined) { @@ -91,7 +93,7 @@ export const createContainer = ( const useUpdate = concurrentMode ? () => { if ( - typeof process === 'object' && + hasGlobalProcess && process.env.NODE_ENV !== 'production' && useContextOrig(UpdateContext) === undefined ) { diff --git a/src/createTrackedSelector.ts b/src/createTrackedSelector.ts index fe0ec28f..31e41844 100644 --- a/src/createTrackedSelector.ts +++ b/src/createTrackedSelector.ts @@ -3,6 +3,8 @@ import { createProxy, isChanged } from 'proxy-compare'; import { useAffectedDebugValue } from './utils.js'; +const hasGlobalProcess = typeof process === 'object'; + export const createTrackedSelector = ( useSelector: (selector: (state: State) => Selected) => Selected, ) => { @@ -38,7 +40,7 @@ export const createTrackedSelector = ( [affected], ); const state = useSelector(selector); - if (typeof process === 'object' && process.env.NODE_ENV !== 'production') { + if (hasGlobalProcess && process.env.NODE_ENV !== 'production') { // eslint-disable-next-line react-hooks/rules-of-hooks useAffectedDebugValue(state, affected); }