Skip to content

Commit

Permalink
[FSSDK-9494] Bug bash & fixes (#214)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
mikechu-optimizely and Mike Chu authored Sep 22, 2023
1 parent de7e992 commit 20cc6cc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"jest.autoRun": {
"onStartup": ["all-tests"]
},
"jest.jestCommandLine": "./node_modules/.bin/jest",
"jest.autoRevealOutput": "on-exec-error"
}
}
28 changes: 16 additions & 12 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -243,19 +243,23 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
this.isClientReady = true;
});

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

// Client and user can become ready synchronously and/or asynchronously. This flag specifically indicates that they became ready asynchronously.
this.isReadyPromiseFulfilled = true;
return {
success: true,
message: 'Successfully resolved datafile and user information.',
};
});
const bothSuccessful = userResult.success && clientResult.success;
return {
success: true, // bothSuccessful,
message: bothSuccessful
? 'Successfully resolved user information and client datafile.'
: 'User information or client datafile was not not ready.',
};
}
);
} else {
logger.warn('Unable to resolve datafile and user information because Optimizely client failed to initialize.');

this.dataReadyPromise = new Promise((resolve, reject) => {
this.dataReadyPromise = new Promise(resolve => {
resolve({
success: false,
reason: 'NO_CLIENT',
Expand Down Expand Up @@ -308,14 +312,14 @@ class OptimizelyReactSDKClient implements ReactSDKClient {

return Promise.race([this.dataReadyPromise, timeoutPromise]).then(async res => {
clearTimeout(timeoutId);
if (res.success) {
if (res.success && !this.initialConfig.odpOptions?.disabled) {
const isSegmentsFetched = await this.fetchQualifiedSegments();
if (!isSegmentsFetched) {
return {
success: false,
reason: 'USER_NOT_READY',
message: 'Failed to fetch qualified segments',
}
};
}
}
return res;
Expand Down
8 changes: 4 additions & 4 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* limitations under the License.
*/
import { useCallback, useContext, useEffect, useState, useRef } from 'react';
import { UserAttributes, OptimizelyDecideOption } from '@optimizely/optimizely-sdk';
import { getLogger } from '@optimizely/optimizely-sdk';
import { LoggerFacade } from '@optimizely/optimizely-sdk/dist/modules/logging';

import { UserAttributes, OptimizelyDecideOption, getLogger } from '@optimizely/optimizely-sdk';

import { setupAutoUpdateListeners } from './autoUpdate';
import { ReactSDKClient, VariableValuesObject, OnReadyResult } from './client';
import { notifier } from './notifier';
import { OptimizelyContext } from './Context';
import { areAttributesEqual, OptimizelyDecision, createFailedDecision } from './utils';

const hooksLogger: LoggerFacade = getLogger('ReactSDK');
const hooksLogger = getLogger('ReactSDK');

enum HookType {
EXPERIMENT = 'Experiment',
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/**
* Copyright 2018-2019, Optimizely
* Copyright 2018-2019, 2023 Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export { OptimizelyContext, OptimizelyContextConsumer, OptimizelyContextProvider } from './Context';
export { OptimizelyProvider } from './Provider';
export { OptimizelyFeature } from './Feature';
Expand All @@ -22,8 +23,7 @@ export { OptimizelyExperiment } from './Experiment';
export { OptimizelyVariation } from './Variation';
export { OptimizelyDecision } from './utils';

export
{
export {
logging,
errorHandler,
setLogger,
Expand All @@ -33,9 +33,9 @@ export
OptimizelyDecideOption,
ActivateListenerPayload,
TrackListenerPayload,
ListenerPayload
}
from '@optimizely/optimizely-sdk';
ListenerPayload,
OptimizelySegmentOption,
} from '@optimizely/optimizely-sdk';

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

Expand Down

0 comments on commit 20cc6cc

Please sign in to comment.