From 5f64c8bbf4b267d8aaaa5eb99d82fcd21eab5fe5 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 11 Oct 2024 17:57:47 -0500 Subject: [PATCH] Bring dev mode checks underneath `process.env.NODE_ENV` references - This was done to ensure that the remaining traces of dev mode checks will not be present in the `'production'` build. --- src/components/Provider.tsx | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/components/Provider.tsx b/src/components/Provider.tsx index d7f633705..5f532c459 100644 --- a/src/components/Provider.tsx +++ b/src/components/Provider.tsx @@ -54,24 +54,32 @@ export interface ProviderProps< children: ReactNode } -function Provider = UnknownAction, S = unknown>({ - store, - context, - children, - serverState, - stabilityCheck = 'once', - identityFunctionCheck = 'once', -}: ProviderProps) { +function Provider = UnknownAction, S = unknown>( + providerProps: ProviderProps, +) { + const { children, context, serverState, store } = providerProps + const contextValue = React.useMemo(() => { const subscription = createSubscription(store) - return { + + const baseContextValue = { store, subscription, getServerState: serverState ? () => serverState : undefined, - stabilityCheck, - identityFunctionCheck, } - }, [store, serverState, stabilityCheck, identityFunctionCheck]) + + if (process.env.NODE_ENV === 'production') { + return baseContextValue + } else { + const { identityFunctionCheck = 'once', stabilityCheck = 'once' } = + providerProps + + return /* @__PURE__ */ Object.assign(baseContextValue, { + stabilityCheck, + identityFunctionCheck, + }) + } + }, [store, serverState]) const previousState = React.useMemo(() => store.getState(), [store])