Skip to content

Commit 1063f4f

Browse files
authored
fix: Redundant activate calls in useExperiment hook (#172)
## Summary In some scenarios, the useExperiment hook was making two activate calls which results in redundant impression events which has a cost impact on the customers. This PR fixes the redundant activate calls. ## Test Plan - Manually tested thoroughly in many scenarios. - All existing tests pass.
1 parent b3b9ed7 commit 1063f4f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10-
- None yet!
10+
### Bug fixes
11+
- Fixed Redundant activate calls in useExperiment hook in a scenario.
1112

1213
## [2.9.0] - June 15, 2022
1314

src/hooks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export const useExperiment: UseExperiment = (experimentKey, options = {}, overri
240240
// and we need to wait for the promise and update decision.
241241
// 2. When client is using datafile only but client is not ready yet which means user
242242
// was provided as a promise and we need to subscribe and wait for user to become available.
243-
if (optimizely.getIsUsingSdkKey() || !isClientReady) {
243+
if ((optimizely.getIsUsingSdkKey() && !optimizely.getIsReadyPromiseFulfilled()) || !isClientReady) {
244244
subscribeToInitialization(optimizely, finalReadyTimeout, initState => {
245245
setState({
246246
...getCurrentDecision(),

0 commit comments

Comments
 (0)