Skip to content

Commit 2a449dd

Browse files
Upgrade JS SDK dependency, and update internal logic to use lastUpdate property from JS SDK clients
1 parent 7bf1b47 commit 2a449dd

File tree

11 files changed

+64
-61
lines changed

11 files changed

+64
-61
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.13.0 (September XX, 2024)
2+
- Updated @splitsoftware/splitio package to version 10.28.0 that includes minor updates:
3+
- Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks.
4+
- Updated some transitive dependencies for vulnerability fixes.
5+
16
1.12.1 (August 2, 2024)
27
- Updated @splitsoftware/splitio package to version 10.27.0 and some transitive dependencies for vulnerability fixes.
38

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"homepage": "https://github.com/splitio/react-client#readme",
6565
"dependencies": {
66-
"@splitsoftware/splitio": "10.27.0",
66+
"@splitsoftware/splitio": "10.28.0-rc.3",
6767
"memoize-one": "^5.1.1",
6868
"shallowequal": "^1.1.0",
6969
"tslib": "^2.3.1"

src/SplitClient.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class SplitComponent extends React.Component<IUpdateProps & { factory: Sp
8686
}
8787

8888
update = () => {
89-
this.setState({ lastUpdate: (this.state.client as IClientWithContext).lastUpdate });
89+
this.setState({ lastUpdate: (this.state.client as IClientWithContext).__getStatus().lastUpdate });
9090
}
9191

9292
componentDidMount() {

src/__tests__/SplitClient.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { SplitFactoryProvider } from '../SplitFactoryProvider';
1515
import { SplitClient } from '../SplitClient';
1616
import { SplitContext } from '../SplitContext';
1717
import { testAttributesBinding, TestComponentProps } from './testUtils/utils';
18+
import { IClientWithContext } from '../utils';
1819

1920
describe('SplitClient', () => {
2021

@@ -55,7 +56,7 @@ describe('SplitClient', () => {
5556
expect(hasTimedout).toBe(false);
5657
expect(isTimedout).toBe(false);
5758
expect(isDestroyed).toBe(false);
58-
expect(lastUpdate).toBe(0);
59+
expect(lastUpdate).toBe((outerFactory.client() as IClientWithContext).__getStatus().lastUpdate);
5960

6061
return null;
6162
}}
@@ -212,7 +213,7 @@ describe('SplitClient', () => {
212213
count++;
213214

214215
// side effect in the render phase
215-
if (!(client as any).__getStatus().isReady) {
216+
if (!(client as IClientWithContext).__getStatus().isReady) {
216217
console.log('emit');
217218
(client as any).__emitter__.emit(Event.SDK_READY);
218219
}

src/__tests__/SplitFactory.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ISplitFactoryChildProps } from '../types';
1515
import { SplitFactory } from '../SplitFactory';
1616
import { SplitClient } from '../SplitClient';
1717
import { SplitContext } from '../SplitContext';
18-
import { __factories } from '../utils';
18+
import { __factories, IClientWithContext } from '../utils';
1919
import { WARN_SF_CONFIG_AND_FACTORY, ERROR_SF_NO_CONFIG_AND_FACTORY } from '../constants';
2020

2121
describe('SplitFactory', () => {
@@ -54,7 +54,7 @@ describe('SplitFactory', () => {
5454
expect(hasTimedout).toBe(false);
5555
expect(isTimedout).toBe(false);
5656
expect(isDestroyed).toBe(false);
57-
expect(lastUpdate).toBe(0);
57+
expect(lastUpdate).toBe((outerFactory.client() as IClientWithContext).__getStatus().lastUpdate);
5858
expect((factory as SplitIO.ISDK).settings.version).toBe(outerFactory.settings.version);
5959
return null;
6060
}}

src/__tests__/SplitFactoryProvider.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ISplitFactoryChildProps } from '../types';
1515
import { SplitFactoryProvider } from '../SplitFactoryProvider';
1616
import { SplitClient } from '../SplitClient';
1717
import { SplitContext } from '../SplitContext';
18-
import { __factories } from '../utils';
18+
import { __factories, IClientWithContext } from '../utils';
1919
import { WARN_SF_CONFIG_AND_FACTORY } from '../constants';
2020

2121
describe('SplitFactoryProvider', () => {
@@ -54,7 +54,7 @@ describe('SplitFactoryProvider', () => {
5454
expect(hasTimedout).toBe(false);
5555
expect(isTimedout).toBe(false);
5656
expect(isDestroyed).toBe(false);
57-
expect(lastUpdate).toBe(0);
57+
expect(lastUpdate).toBe((outerFactory.client() as IClientWithContext).__getStatus().lastUpdate);
5858
expect((factory as SplitIO.ISDK).settings.version).toBe(outerFactory.settings.version);
5959
return null;
6060
}}

src/__tests__/SplitTreatments.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jest.mock('@splitsoftware/splitio/client', () => {
88
});
99
import { SplitFactory as SplitSdk } from '@splitsoftware/splitio/client';
1010
import { sdkBrowser } from './testUtils/sdkConfigs';
11-
import { getStatus } from '../utils';
11+
import { getStatus, IClientWithContext } from '../utils';
1212
import { newSplitFactoryLocalhostInstance } from './testUtils/utils';
1313
import { CONTROL_WITH_CONFIG } from '../constants';
1414

@@ -70,7 +70,7 @@ describe('SplitTreatments', () => {
7070
expect(clientMock.getTreatmentsWithConfig.mock.calls.length).toBe(1);
7171
expect(treatments).toBe(clientMock.getTreatmentsWithConfig.mock.results[0].value);
7272
expect(featureFlagNames).toBe(clientMock.getTreatmentsWithConfig.mock.calls[0][0]);
73-
expect([isReady2, isReadyFromCache, hasTimedout, isTimedout, isDestroyed, lastUpdate]).toStrictEqual([true, false, false, false, false, 0]);
73+
expect([isReady2, isReadyFromCache, hasTimedout, isTimedout, isDestroyed, lastUpdate]).toStrictEqual([true, false, false, false, false, (outerFactory.client() as IClientWithContext).__getStatus().lastUpdate]);
7474
return null;
7575
}}
7676
</SplitTreatments>

src/__tests__/testUtils/mockSplitSdk.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,22 @@ function buildInstanceId(key: any, trafficType: string | undefined) {
3232

3333
function mockClient(_key: SplitIO.SplitKey, _trafficType?: string) {
3434
// Readiness
35-
let __isReady__: boolean | undefined;
36-
let __isReadyFromCache__: boolean | undefined;
37-
let __hasTimedout__: boolean | undefined;
38-
let __isDestroyed__: boolean | undefined;
35+
let isReady = false;
36+
let isReadyFromCache = false;
37+
let hasTimedout = false;
38+
let isDestroyed = false;
39+
let lastUpdate = 0;
40+
41+
function syncLastUpdate() {
42+
const dateNow = Date.now();
43+
lastUpdate = dateNow > lastUpdate ? dateNow : lastUpdate + 1;
44+
}
45+
3946
const __emitter__ = new EventEmitter();
40-
__emitter__.on(Event.SDK_READY, () => { __isReady__ = true; });
41-
__emitter__.on(Event.SDK_READY_FROM_CACHE, () => { __isReadyFromCache__ = true; });
42-
__emitter__.on(Event.SDK_READY_TIMED_OUT, () => { __hasTimedout__ = true; });
47+
__emitter__.on(Event.SDK_READY, () => { isReady = true; syncLastUpdate(); });
48+
__emitter__.on(Event.SDK_READY_FROM_CACHE, () => { isReadyFromCache = true; syncLastUpdate(); });
49+
__emitter__.on(Event.SDK_READY_TIMED_OUT, () => { hasTimedout = true; syncLastUpdate(); });
50+
__emitter__.on(Event.SDK_UPDATE, () => { syncLastUpdate(); });
4351

4452
let attributesCache = {};
4553

@@ -72,21 +80,23 @@ function mockClient(_key: SplitIO.SplitKey, _trafficType?: string) {
7280
});
7381
const ready: jest.Mock = jest.fn(() => {
7482
return new Promise<void>((res, rej) => {
75-
if (__isReady__) res();
83+
if (isReady) res();
7684
else { __emitter__.on(Event.SDK_READY, res); }
77-
if (__hasTimedout__) rej();
85+
if (hasTimedout) rej();
7886
else { __emitter__.on(Event.SDK_READY_TIMED_OUT, rej); }
7987
});
8088
});
8189
const __getStatus = () => ({
82-
isReady: __isReady__ || false,
83-
isReadyFromCache: __isReadyFromCache__ || false,
84-
hasTimedout: __hasTimedout__ || false,
85-
isDestroyed: __isDestroyed__ || false,
86-
isOperational: ((__isReady__ || __isReadyFromCache__) && !__isDestroyed__) || false,
90+
isReady,
91+
isReadyFromCache,
92+
hasTimedout,
93+
isDestroyed,
94+
isOperational: (isReady || isReadyFromCache) && !isDestroyed,
95+
lastUpdate,
8796
});
8897
const destroy: jest.Mock = jest.fn(() => {
89-
__isDestroyed__ = true;
98+
isDestroyed = true;
99+
syncLastUpdate();
90100
// __emitter__.removeAllListeners();
91101
return Promise.resolve();
92102
});
@@ -108,7 +118,8 @@ function mockClient(_key: SplitIO.SplitKey, _trafficType?: string) {
108118
// Restore the mock client to its initial NO-READY status.
109119
// Useful when you want to reuse the same mock between tests after emitting events or destroying the instance.
110120
__restore() {
111-
__isReady__ = __isReadyFromCache__ = __hasTimedout__ = __isDestroyed__ = undefined;
121+
isReady = isReadyFromCache = hasTimedout = isDestroyed = false;
122+
lastUpdate = 0;
112123
}
113124
});
114125
}

src/useSplitClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function useSplitClient(options?: IUseSplitClientOptions): ISplitContextV
4545
React.useEffect(() => {
4646
if (!client) return;
4747

48-
const update = () => setLastUpdate(client.lastUpdate);
48+
const update = () => setLastUpdate(client.__getStatus().lastUpdate);
4949

5050
// Clients are created on the hook's call, so the status may have changed
5151
const statusOnEffect = getStatus(client);

0 commit comments

Comments
 (0)