Skip to content

Commit 6bfb15b

Browse files
Polishing
1 parent 833d6c9 commit 6bfb15b

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- Added support for targeting rules based on large segments for browsers.
33
- Updated @splitsoftware/splitio package to version 11.0.0 that includes major updates, and updated some transitive dependencies for vulnerability fixes.
44
- Renamed distribution folders from `/lib` to `/cjs` for CommonJS build, and `/es` to `/esm` for EcmaScript Modules build.
5-
- Bugfixing - When the `config` prop is provided, the `SplitFactoryProvider` now makes the SDK factory and client instances available in the context immediately during the initial render, instead of waiting for the first SDK event. This change fixes a bug in the `useTrack` hook, which was not retrieving the client's `track` method during the initial render but rather a no-op function.
5+
- Bugfixing - When the `config` prop is provided, the `SplitFactoryProvider` now makes the SDK factory and client instances available in the context immediately during the initial render, instead of waiting for the first SDK event (Related to https://github.com/splitio/react-client/issues/198). This change fixes a bug in the `useTrack` hook, which was not retrieving the client's `track` method during the initial render.
66
- BREAKING CHANGES:
77
- Updated error handling: using the library modules without wrapping them in a `SplitFactoryProvider` component will now throw an error instead of logging it, as the modules requires the `SplitContext` to work properly.
88
- Removed the `core.trafficType` configuration option and the `trafficType` parameter from the SDK `client()` method, `useSplitClient`, `useTrack`, and `SplitClient` component. This is because traffic types can no longer be bound to SDK clients in JavaScript SDK v11.0.0, and so the traffic type must be provided as first argument in the `track` method calls.

src/__tests__/useTrack.test.tsx

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,7 @@ describe('useTrack', () => {
2323
const value = 10;
2424
const properties = { prop1: 'prop1' };
2525

26-
test('returns the track method of the client at Split context updated by SplitFactoryProvider (config prop).', () => {
27-
render(
28-
<SplitFactoryProvider config={sdkBrowser} >
29-
{React.createElement(() => {
30-
const clientTrack = useTrack();
31-
32-
const { client } = useSplitClient();
33-
expect(clientTrack).toBe(client!.track);
34-
35-
clientTrack(tt, eventType, value, properties);
36-
37-
useEffect(() => {
38-
clientTrack(tt, eventType, value, properties);
39-
}, [clientTrack]);
40-
return null;
41-
})}
42-
</SplitFactoryProvider>,
43-
);
44-
45-
act(() => getLastInstance(SplitFactory).client().__emitter__.emit(Event.SDK_READY_FROM_CACHE));
46-
act(() => getLastInstance(SplitFactory).client().__emitter__.emit(Event.SDK_READY));
47-
48-
const track = getLastInstance(SplitFactory).client().track as jest.Mock;
49-
expect(track).toBeCalledWith(tt, eventType, value, properties);
50-
expect(track).toBeCalledTimes(4); // 3 from render + 1 from useEffect (`clientTrack` dependency doesn't change)
51-
});
52-
53-
test('returns the track method of the client at Split context updated by SplitFactoryProvider (factory prop).', () => {
26+
test('returns the track method of the client at Split context updated by SplitFactoryProvider.', () => {
5427
const outerFactory = SplitFactory(sdkBrowser);
5528
let clientTrack;
5629
let trackResult;
@@ -121,4 +94,38 @@ describe('useTrack', () => {
12194
}).toThrow(EXCEPTION_NO_SFP);
12295
});
12396

97+
test('returns the track method of the client at Split context updated by SplitFactoryProvider (config prop).', () => {
98+
let splitKey: string | undefined = undefined;
99+
render(
100+
<SplitFactoryProvider config={sdkBrowser} updateOnSdkUpdate={true} >
101+
{React.createElement(() => {
102+
const clientTrack = useTrack(splitKey);
103+
104+
const { client } = useSplitClient({ splitKey });
105+
expect(clientTrack).toBe(client!.track);
106+
107+
clientTrack(tt, eventType, value, properties);
108+
109+
useEffect(() => {
110+
clientTrack(tt, eventType, value, properties);
111+
}, [clientTrack]);
112+
return null;
113+
})}
114+
</SplitFactoryProvider>,
115+
);
116+
117+
act(() => getLastInstance(SplitFactory).client().__emitter__.emit(Event.SDK_READY_FROM_CACHE));
118+
act(() => getLastInstance(SplitFactory).client().__emitter__.emit(Event.SDK_READY));
119+
splitKey = 'user2'; // `clientTrack` dependency changed
120+
act(() => getLastInstance(SplitFactory).client().__emitter__.emit(Event.SDK_UPDATE));
121+
122+
let track = getLastInstance(SplitFactory).client().track as jest.Mock;
123+
expect(track).toBeCalledWith(tt, eventType, value, properties);
124+
expect(track).toBeCalledTimes(4); // 3 from render + 1 from useEffect
125+
126+
track = getLastInstance(SplitFactory).client('user2').track as jest.Mock;
127+
expect(track).toBeCalledWith(tt, eventType, value, properties);
128+
expect(track).toBeCalledTimes(2); // 1 from render + 1 from useEffect (`clientTrack` dependency changed)
129+
});
130+
124131
});

0 commit comments

Comments
 (0)