Skip to content

Commit 013a610

Browse files
authored
fix: Remove unnecessary withOptimizely usage from Experiment and Feature components, and fix timeout log message (#42)
Summary: Experiment and Feature were refactored to use hooks internally. Now, they access the context set by OptimizelyProvider via useContext, so there's no need to use withOptimizely on them. In this PR I removed withOptimizely from those components, and fixed a log message related to timeout so that it shows the correct timeout when a component timeout prop was used. Test Plan: Manually tested, existing unit tests pass
1 parent 7f78f5c commit 013a610

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/Experiment.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ import { UserAttributes } from '@optimizely/optimizely-sdk';
1919

2020
import { useExperiment } from './hooks';
2121
import { VariationProps } from './Variation';
22-
import { withOptimizely, WithOptimizelyProps } from './withOptimizely';
2322

2423
export type ChildrenRenderFunction = (
2524
variation: string | null,
2625
clientReady?: boolean,
2726
didTimeout?: boolean
2827
) => React.ReactNode;
2928

30-
export interface ExperimentProps extends WithOptimizelyProps {
29+
export interface ExperimentProps {
3130
// TODO add support for overrideUserId
3231
experiment: string;
3332
autoUpdate?: boolean;
@@ -78,4 +77,4 @@ const Experiment: React.FunctionComponent<ExperimentProps> = props => {
7877
return match ? React.cloneElement(match, { variation }) : null;
7978
};
8079

81-
export const OptimizelyExperiment = withOptimizely(Experiment);
80+
export const OptimizelyExperiment = Experiment;

src/Feature.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { UserAttributes } from '@optimizely/optimizely-sdk';
1818

1919
import { VariableValuesObject } from './client';
2020
import { useFeature } from './hooks';
21-
import { withOptimizely, WithOptimizelyProps } from './withOptimizely';
2221

2322
export type ChildrenRenderFunction = (
2423
isEnabled: boolean,
@@ -27,7 +26,7 @@ export type ChildrenRenderFunction = (
2726
didTimeout: boolean
2827
) => React.ReactNode;
2928

30-
export interface FeatureProps extends WithOptimizelyProps {
29+
export interface FeatureProps {
3130
feature: string;
3231
timeout?: number;
3332
autoUpdate?: boolean;
@@ -54,4 +53,4 @@ const FeatureComponent: React.FunctionComponent<FeatureProps> = props => {
5453
return <>{children(isEnabled, variables, clientReady, didTimeout)}</>;
5554
};
5655

57-
export const OptimizelyFeature = withOptimizely(FeatureComponent);
56+
export const OptimizelyFeature = FeatureComponent;

src/hooks.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ const initializeWhenClientReadyFn = (
110110
return;
111111
}
112112
setState((state: HookState) => ({ ...state, didTimeout: true }));
113-
logger.info(`${type}="${name}" could not be set before timeout of ${timeout}ms, reason="${res.reason || ''}"`);
113+
logger.info(
114+
`${type}="${name}" could not be set before timeout of ${finalReadyTimeout}ms, reason="${res.reason || ''}"`
115+
);
114116
// Since we timed out, wait for the dataReadyPromise to resolve before setting up.
115117
return res.dataReadyPromise!.then(() => {
116118
logger.info(`${type}="${name}" is now set, but after timeout.`);

0 commit comments

Comments
 (0)