Skip to content

Commit 20cc6cc

Browse files
mikechu-optimizelyMike Chu
andauthored
[FSSDK-9494] Bug bash & fixes (#214)
* Remove devcontainer comments * Testing bug bash devcontainer config * Remove the separate dev container conf * Add setup & exec as npm scripts * Use LF by default when in devcontainer * Update jest config * Update JS SDK via yarn.lock * Convert to TS for bug bash * Prompt for SDK key for the bug bash * Ignore the .env file * Enhance setup.sh * Conditionally npm * Change back to scripty .js * Add boilerplate React bug-bash/app * Update setup.sh to install + run React app * Update npm script to run bug-bash * Simplify setup.sh * Simplify the react app * WIP: Update App + use local @optimizely/react-sdk * Add local React & dotenv * Update setup script * Remove dotenv * WIP bring .env values in * Complete WIP on reading SDK from .env * Transfer @rafinutshaw-optimizely's work in * Small style fix * Minor semantic HTML changes * A bunch'o NITs for my comfort * Rename bug-bash setup & add run * Ensure shell scripts use LF line endings * WIP testing & refactoring tests * Better doc & UI + Refactors * Move Decision; Finish refactor existing tests * Add more tests based on spreadsheet\ * Add sendOdpEvent tests * Last bits of documentation * Update to use js sdk 5.0.0-beta4 * WIP test updates * Update path to logging due to re-organized JS SDK * Update bug bash to package-lock.json * Add @types/uuid 🤔 * Use /lib/ instead of /dist/ from JS SDK * Reset for other bashers * Add more documentation * Upgrade vulnerable tough-cookie to v4.1.3 * Add "repository" field to package.json Thanks @iamstarkov * Add `useContext` documentation from... @raphaeleidus in #165 * Add EOF lines * Remove React.StrictMode * Remove Vite icon ref * Add decision button to change userId * Remove variationKey validation * Upgrade to JS SDK 5.0.0-beta5 * Fix references to remove /lib * WIP: Fixing getLogger ref from JS 5-beta5 * Explicitly optimizeDep-endcy JS SDK * Export OptimizelySegmentOption from JS SDK * Use OptimizelySegmentOption from React SDK export * Update bug bash package-lock * Remove optimizeDeps from viteconfig * Add test comment * Changed optimizelyClient init location in BB app * Add VSCode launch.json * Add conditional to auto fetchQualifiedSegments * Format .vscode files * Leave out tough-cookie dep * Minor clean ups * Update package-json * PR review change * Remove bug bash app * Refinement of PR request WIP Fix tests that fail if dataReadyPromise resolves success=false * PR correction * Remove VSC lauch.json since no bug-bash --------- Co-authored-by: Mike Chu <[email protected]>
1 parent de7e992 commit 20cc6cc

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

.vscode/settings.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"jest.autoRun": {
33
"onStartup": ["all-tests"]
4-
},
5-
"jest.jestCommandLine": "./node_modules/.bin/jest",
6-
"jest.autoRevealOutput": "on-exec-error"
4+
}
75
}

src/client.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -243,19 +243,23 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
243243
this.isClientReady = true;
244244
});
245245

246-
this.dataReadyPromise = Promise.all([this.userPromise, this._client!.onReady()]).then(res => {
246+
this.dataReadyPromise = Promise.all([this.userPromise, this._client.onReady()]).then(
247+
([userResult, clientResult]) => {
248+
this.isReadyPromiseFulfilled = true;
247249

248-
// Client and user can become ready synchronously and/or asynchronously. This flag specifically indicates that they became ready asynchronously.
249-
this.isReadyPromiseFulfilled = true;
250-
return {
251-
success: true,
252-
message: 'Successfully resolved datafile and user information.',
253-
};
254-
});
250+
const bothSuccessful = userResult.success && clientResult.success;
251+
return {
252+
success: true, // bothSuccessful,
253+
message: bothSuccessful
254+
? 'Successfully resolved user information and client datafile.'
255+
: 'User information or client datafile was not not ready.',
256+
};
257+
}
258+
);
255259
} else {
256260
logger.warn('Unable to resolve datafile and user information because Optimizely client failed to initialize.');
257261

258-
this.dataReadyPromise = new Promise((resolve, reject) => {
262+
this.dataReadyPromise = new Promise(resolve => {
259263
resolve({
260264
success: false,
261265
reason: 'NO_CLIENT',
@@ -308,14 +312,14 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
308312

309313
return Promise.race([this.dataReadyPromise, timeoutPromise]).then(async res => {
310314
clearTimeout(timeoutId);
311-
if (res.success) {
315+
if (res.success && !this.initialConfig.odpOptions?.disabled) {
312316
const isSegmentsFetched = await this.fetchQualifiedSegments();
313317
if (!isSegmentsFetched) {
314318
return {
315319
success: false,
316320
reason: 'USER_NOT_READY',
317321
message: 'Failed to fetch qualified segments',
318-
}
322+
};
319323
}
320324
}
321325
return res;

src/hooks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
* limitations under the License.
1515
*/
1616
import { useCallback, useContext, useEffect, useState, useRef } from 'react';
17-
import { UserAttributes, OptimizelyDecideOption } from '@optimizely/optimizely-sdk';
18-
import { getLogger } from '@optimizely/optimizely-sdk';
19-
import { LoggerFacade } from '@optimizely/optimizely-sdk/dist/modules/logging';
17+
18+
import { UserAttributes, OptimizelyDecideOption, getLogger } from '@optimizely/optimizely-sdk';
19+
2020
import { setupAutoUpdateListeners } from './autoUpdate';
2121
import { ReactSDKClient, VariableValuesObject, OnReadyResult } from './client';
2222
import { notifier } from './notifier';
2323
import { OptimizelyContext } from './Context';
2424
import { areAttributesEqual, OptimizelyDecision, createFailedDecision } from './utils';
2525

26-
const hooksLogger: LoggerFacade = getLogger('ReactSDK');
26+
const hooksLogger = getLogger('ReactSDK');
2727

2828
enum HookType {
2929
EXPERIMENT = 'Experiment',

src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
/**
2-
* Copyright 2018-2019, Optimizely
2+
* Copyright 2018-2019, 2023 Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
export { OptimizelyContext, OptimizelyContextConsumer, OptimizelyContextProvider } from './Context';
1718
export { OptimizelyProvider } from './Provider';
1819
export { OptimizelyFeature } from './Feature';
@@ -22,8 +23,7 @@ export { OptimizelyExperiment } from './Experiment';
2223
export { OptimizelyVariation } from './Variation';
2324
export { OptimizelyDecision } from './utils';
2425

25-
export
26-
{
26+
export {
2727
logging,
2828
errorHandler,
2929
setLogger,
@@ -33,9 +33,9 @@ export
3333
OptimizelyDecideOption,
3434
ActivateListenerPayload,
3535
TrackListenerPayload,
36-
ListenerPayload
37-
}
38-
from '@optimizely/optimizely-sdk';
36+
ListenerPayload,
37+
OptimizelySegmentOption,
38+
} from '@optimizely/optimizely-sdk';
3939

4040
export { createInstance, ReactSDKClient } from './client';
4141

0 commit comments

Comments
 (0)