@@ -249,6 +249,15 @@ function useCompareAttrsMemoize(value: UserAttributes | undefined): UserAttribut
249249 return ref . current ;
250250}
251251
252+ function hasConfigAndUserInfo ( optimizely : ReactSDKClient | null ) : boolean {
253+ const hasConfig = ! ! optimizely ?. getOptimizelyConfig ( ) ;
254+ const userContext = optimizely ?. getUserContext ( ) ;
255+ // @ts -ignore
256+ const isOdpIntegrated = optimizely ?. _client ?. isOdpIntegrated ( ) ;
257+ const areSegmentsAvailable = ! ! ( isOdpIntegrated && userContext ?. qualifiedSegments !== undefined ) ;
258+ return ! ! ( hasConfig && userContext && ( ! isOdpIntegrated || areSegmentsAvailable ) ) ;
259+ }
260+
252261/**
253262 * A React Hook that retrieves the variation for an experiment, optionally
254263 * auto updating that value based on underlying user or datafile changes.
@@ -270,9 +279,10 @@ export const useExperiment: UseExperiment = (experimentKey, options = {}, overri
270279
271280 const isClientReady = isServerSide || ! ! optimizely ?. isReady ( ) ;
272281 const isReadyPromiseFulfilled = ! ! optimizely ?. getIsReadyPromiseFulfilled ( ) ;
273- const canMakeDecision = ! ! ( optimizely ?. getOptimizelyConfig ( ) && optimizely . getUserContext ( ) ) ;
282+ const isExperimentReady = hasConfigAndUserInfo ( optimizely ) || isClientReady ;
283+
274284 const [ state , setState ] = useState < ExperimentDecisionValues & InitializationState > ( ( ) => {
275- const decisionState = canMakeDecision ? getCurrentDecision ( ) : { variation : null } ;
285+ const decisionState = isExperimentReady ? getCurrentDecision ( ) : { variation : null } ;
276286 return {
277287 ...decisionState ,
278288 clientReady : isClientReady ,
@@ -368,10 +378,10 @@ export const useFeature: UseFeature = (featureKey, options = {}, overrides = {})
368378
369379 const isClientReady = isServerSide || ! ! optimizely ?. isReady ( ) ;
370380 const isReadyPromiseFulfilled = ! ! optimizely ?. getIsReadyPromiseFulfilled ( ) ;
371- const canMakeDecision = ! ! ( optimizely ?. getOptimizelyConfig ( ) && optimizely . getUserContext ( ) ) ;
381+ const isFeatureReady = hasConfigAndUserInfo ( optimizely ) || isClientReady ;
372382
373383 const [ state , setState ] = useState < FeatureDecisionValues & InitializationState > ( ( ) => {
374- const decisionState = canMakeDecision ? getCurrentDecision ( ) : { isEnabled : false , variables : { } } ;
384+ const decisionState = isFeatureReady ? getCurrentDecision ( ) : { isEnabled : false , variables : { } } ;
375385 return {
376386 ...decisionState ,
377387 clientReady : isClientReady ,
@@ -468,10 +478,11 @@ export const useDecision: UseDecision = (flagKey, options = {}, overrides = {})
468478
469479 const isClientReady = isServerSide || ! ! optimizely ?. isReady ( ) ;
470480 const isReadyPromiseFulfilled = ! ! optimizely ?. getIsReadyPromiseFulfilled ( ) ;
471- const canMakeDecision = ! ! ( optimizely ?. getOptimizelyConfig ( ) && optimizely . getUserContext ( ) ) ;
481+
482+ const isDecisionReady = hasConfigAndUserInfo ( optimizely ) || isClientReady ;
472483
473484 const [ state , setState ] = useState < { decision : OptimizelyDecision } & InitializationState > ( ( ) => {
474- const decisionState = canMakeDecision
485+ const decisionState = isDecisionReady
475486 ? getCurrentDecision ( )
476487 : {
477488 decision : defaultDecision ,
0 commit comments