Skip to content

Commit 3a01a5c

Browse files
Merge pull request #220 from splitio/development
Add MIGRATION-GUIDE.md file
2 parents 4b353cf + 0319bdb commit 3a01a5c

File tree

5 files changed

+262
-7
lines changed

5 files changed

+262
-7
lines changed

.github/workflows/ci-cd.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
fetch-depth: 0
2929

30-
- name: Set up nodejs
30+
- name: Set up Node.js
3131
uses: actions/setup-node@v3
3232
with:
3333
node-version: 'lts/*'

CHANGES.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
- Renamed distribution folders from `/lib` to `/cjs` for CommonJS build, and `/es` to `/esm` for ECMAScript Modules build.
66
- 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.
77
- BREAKING CHANGES:
8+
- NOTE: Refer to ./MIGRATION-GUIDE.md for instructions on how to migrate your codebase from version 1.x to 2.0.0.
89
- Updated the default value of the `updateOnSdkUpdate` and `updateOnSdkTimedout` parameters of the `useSplitClient` and `useSplitTreatments` hooks options object to `true`, to re-render on all SDK events by default. The same applies for the equivalent props in the `[with]SplitClient` and `[with]SplitTreatments` components.
910
- 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.
10-
- Updated the `SplitFactoryProvider` component to not accept a child as a function (render prop), to avoid unnecessary re-renders when using the library hooks. Refer to ./MIGRATION-GUIDE.md for instructions on how to migrate the child as a function to a regular component.
11+
- Updated the `SplitFactoryProvider` component to not accept a child as a function (render prop), to avoid unnecessary re-renders when using the library hooks. Refer to ./MIGRATION-GUIDE.md for instructions on how to migrate your component to be passed as a regular React JSX element if you were using this pattern.
1112
- Removed the `core.trafficType` option from the SDK configuration object, and the `trafficType` parameter from the SDK `client()` method, `useSplitClient`, `useTrack`, `withSplitClient` 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.
1213
- Removed deprecated modules: `SplitFactory` component, `useClient`, `useTreatments` and `useManager` hooks. Refer to ./MIGRATION-GUIDE.md for instructions on how to migrate to the new alternatives.
1314
- Renamed `SplitSdk` to `SplitFactory` function, which is the underlying Split SDK factory, i.e., `import { SplitFactory } from '@splitsoftware/splitio'`.

MIGRATION-GUIDE.md

+256
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,260 @@
11

2+
# Migrating to React SDK v2.0.0
3+
4+
React SDK v2.0.0 has a few breaking changes that you should consider when migrating from a previous version. The main changes are:
5+
6+
### • Deprecated `useClient`, `useTreatments`, and `useManager` hooks have been removed.
7+
8+
Follow [this section](#migrating-to-get-react-sdk-v1100-improvements-replacing-the-deprecated-useclient-usetreatments-and-usemanager-hooks) to migrate to the new hooks `useSplitClient`, `useSplitTreatments`, and `useSplitManager`.
9+
10+
### • Deprecated `SplitFactory` provider has been removed, `withSplitFactory` is deprecated, and `SplitFactoryProvider` doesn't accept `updateOn` props and a render function as children anymore.
11+
12+
To migrate your existing code to the new version of `SplitFactoryProvider`, consider the following refactor example:
13+
14+
```tsx
15+
const MyComponent = (props: ISplitContextValues) => {
16+
const { factory, client, isReady, isReadyFromCache, ... } = props;
17+
...
18+
};
19+
20+
// if using SplitFactoryProvider v1.11.0
21+
const App = () => {
22+
return (
23+
<SplitFactoryProvider config={mySplitConfig} updateOnSdkUpdate={false} attributes={DEFAULT_CLIENT_ATTRIBUTES} >
24+
{MyComponent}
25+
</SplitFactoryProvider>
26+
);
27+
};
28+
29+
// or SplitFactory
30+
const App = () => {
31+
return (
32+
<SplitFactory config={mySplitConfig} updateOnSdkUpdate={false} attributes={DEFAULT_CLIENT_ATTRIBUTES} >
33+
{MyComponent}
34+
</SplitFactory>
35+
);
36+
};
37+
38+
// or withSplitFactory
39+
const App = withSplitFactory(mySplitConfig, undefined, DEFAULT_CLIENT_ATTRIBUTES)(
40+
MyComponent, false /* updateOnSdkUpdate = false */
41+
);
42+
```
43+
44+
should be refactored to:
45+
46+
```tsx
47+
const MyComponent = () => {
48+
const props: ISplitContextValues = useSplitClient({ updateOnSdkUpdate: false });
49+
const { factory, client, isReady, isReadyFromCache, ... } = props;
50+
...
51+
};
52+
53+
const App = () => {
54+
return (
55+
<SplitFactoryProvider config={mySplitConfig} attributes={DEFAULT_CLIENT_ATTRIBUTES} >
56+
<MyComponent />
57+
</SplitFactoryProvider>
58+
);
59+
};
60+
```
61+
62+
Notice that `MyComponent` was refactored to use the `useSplitClient` hook and is passed as a React JSX element rather than a render function. The `useSplitClient` hook is called without providing a `splitKey` param. This means that the default client (whose key is set in the `core.key` property of the `mySplitConfig` object) will be used, and the `updateOn` and `attributes` props are passed as options to the hook.
63+
64+
### • High-Order-Components (`withSplitClient`, `withSplitTreatments`) and components that accept a render function as child component (`SplitTreatments`, and `SplitClient`) have been deprecated and might be removed in a future major release.
65+
66+
The deprecation is intended to simplify the API and discourage using old patterns (HOCs and render props) in favor of the *hook* alternatives, to take advantage of React optimizations.
67+
68+
To migrate your existing code based on `withSplitClient` or `SplitClient`, consider the following refactor using the `useSplitClient` hook:
69+
70+
```tsx
71+
const MyComponent = (props: ISplitContextValues) => {
72+
const { client, isReady, ... } = props;
73+
...
74+
};
75+
76+
const App = withSplitFactory(mySplitConfig)(
77+
withSplitClient(OTHER_KEY, OTHER_KEY_ATTRIBUTES)(
78+
MyComponent, undefined, undefined, undefined, false /* updateOnSdkReadyFromCache = false */
79+
)
80+
);
81+
82+
// or
83+
const App = () => {
84+
return (
85+
<SplitFactory config={mySplitConfig} >
86+
<SplitClient splitKey={OTHER_KEY} attributes={OTHER_KEY_ATTRIBUTES} updateOnSdkReadyFromCache={false} >
87+
{MyComponent}
88+
</SplitClient>
89+
</SplitFactory>
90+
)
91+
};
92+
```
93+
94+
should be refactored to:
95+
96+
```tsx
97+
const MyComponent = () => {
98+
const props: ISplitContextValues = useSplitClient({ splitKey: OTHER_KEY, attributes: OTHER_KEY_ATTRIBUTES, updateOnSdkReadyFromCache: false });
99+
const { client, isReady, ... } = props;
100+
...
101+
};
102+
103+
const App = () => {
104+
return (
105+
<SplitFactoryProvider config={mySplitConfig} >
106+
<MyComponent />
107+
</SplitFactory>
108+
)
109+
};
110+
```
111+
112+
To migrate your existing code based on `withSplitTreatments` or `SplitTreatments`, consider the following refactor using the `useSplitTreatments` hook:
113+
114+
```tsx
115+
const MyComponent = (props: ISplitTreatmentsChildProps) => {
116+
const { treatments, isReady, ... } = props;
117+
...
118+
};
119+
120+
const App = withSplitFactory(mySplitConfig)(
121+
withSplitClient(OTHER_KEY)(
122+
withSplitTreatments(FEATURE_FLAG_NAMES, ATTRIBUTES)(
123+
MyComponent
124+
)
125+
)
126+
);
127+
128+
// or
129+
const App = () => {
130+
return (
131+
<SplitFactory config={mySplitConfig} >
132+
<SplitClient splitKey={OTHER_KEY} >
133+
<SplitTreatments names={FEATURE_FLAG_NAMES} attributes={ATTRIBUTES} >
134+
{MyComponent}
135+
</SplitTreatments>
136+
</SplitClient>
137+
</SplitFactory>
138+
)
139+
};
140+
```
141+
142+
should be refactored to:
143+
144+
```tsx
145+
const MyComponent = () => {
146+
const props: ISplitTreatmentsChildProps = useSplitTreatments({ splitKey: OTHER_KEY, names: FEATURE_FLAG_NAMES, attributes: ATTRIBUTES });
147+
const { treatments, isReady, ... } = props;
148+
...
149+
};
150+
151+
const App = () => {
152+
return (
153+
<SplitFactoryProvider config={mySplitConfig} >
154+
<MyComponent />
155+
</SplitFactory>
156+
)
157+
};
158+
```
159+
160+
### • Renamed `SplitSdk` function to `SplitFactory`.
161+
162+
If you are using the `SplitSdk` function to create a factory and pass it to the `SplitFactoryProvider` component, you should rename it to `SplitFactory`. For example:
163+
164+
```tsx
165+
import { SplitSdk, SplitFactoryProvider } from '@splitsoftware/splitio-react';
166+
167+
const myFactory = SplitSdk(mySplitConfig);
168+
169+
const App = () => {
170+
return (
171+
<SplitFactoryProvider factory={myFactory} >
172+
<MyComponent />
173+
</SplitFactoryProvider>
174+
);
175+
};
176+
```
177+
178+
should be refactored to:
179+
180+
```tsx
181+
import { SplitFactory, SplitFactoryProvider } from '@splitsoftware/splitio-react';
182+
183+
const myFactory = SplitFactory(mySplitConfig);
184+
185+
const App = () => {
186+
return (
187+
<SplitFactoryProvider factory={myFactory} >
188+
<MyComponent />
189+
</SplitFactoryProvider>
190+
);
191+
};
192+
```
193+
194+
### • Traffic type cannot be bound to SDK clients anymore.
195+
196+
If you were passing the `trafficType` to the SDK config, `useSplitClient` hook, or `useTrack` hook, you should remove it. The `trafficType` must now be passed as the first argument of the `track` method. For example:
197+
198+
```tsx
199+
const mySplitConfig = {
200+
core: {
201+
authorizationKey: YOUR_CLIENT_SIDE_SDK_KEY,
202+
key: USER_KEY,
203+
trafficType: 'user'
204+
}
205+
}
206+
207+
const MyComponent = () => {
208+
const track = useTrack();
209+
const accountTrack = useTrack(ACCOUNT_KEY, 'account');
210+
211+
useEffect(() => {
212+
track('my_event');
213+
accountTrack('my_event');
214+
}, []);
215+
216+
...
217+
};
218+
219+
const App = () => {
220+
return (
221+
<SplitFactoryProvider config={mySplitConfig} >
222+
<MyComponent />
223+
</SplitFactory>
224+
)
225+
};
226+
```
227+
228+
should be refactored to:
229+
230+
```tsx
231+
const mySplitConfig = {
232+
core: {
233+
authorizationKey: YOUR_CLIENT_SIDE_SDK_KEY,
234+
key: USER_KEY
235+
}
236+
}
237+
238+
const MyComponent = () => {
239+
const track = useTrack();
240+
const accountTrack = useTrack(ACCOUNT_KEY);
241+
242+
useEffect(() => {
243+
track('user', 'my_event');
244+
accountTrack('account', 'my_event');
245+
}, []);
246+
...
247+
};
248+
249+
const App = () => {
250+
return (
251+
<SplitFactoryProvider config={mySplitConfig} >
252+
<MyComponent />
253+
</SplitFactory>
254+
)
255+
};
256+
```
257+
2258
# Migrating to get React SDK v1.11.0 improvements: Replacing the deprecated `SplitFactory` and `withSplitFactory` components
3259

4260
Starting from React SDK v1.11.0, the `SplitFactoryProvider` component is available and can replace the older `SplitFactory` and `withSplitFactory` components. The deprecated components will continue working, until they are removed in a future major release.

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ This SDK is designed to work with Split, the platform for controlled rollouts, w
99

1010
## Compatibility
1111

12-
This SDK is compatible with React 16.3.0 and above, since it uses [React Context API](https://reactjs.org/docs/context.html).
13-
14-
Some features, such as `useSplitClient` and `useSplitTreatments`, use [React Hooks API](https://reactjs.org/docs/hooks-overview.html) that requires React 16.8.0 or later.
12+
This SDK is compatible with React 16.8.0 and above, since it uses [React Hooks API](https://react.dev/reference/react/hooks) introduced in that version.
1513

1614
## Getting started
1715
Below is a simple example that describes the instantiation and most basic usage of our SDK:
@@ -85,7 +83,7 @@ Split has built and maintains SDKs for:
8583
* Java [Github](https://github.com/splitio/java-client) [Docs](https://help.split.io/hc/en-us/articles/360020405151-Java-SDK)
8684
* JavaScript [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK)
8785
* JavaScript for Browser [Github](https://github.com/splitio/javascript-browser-client) [Docs](https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK)
88-
* Node [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
86+
* Node.js [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
8987
* PHP [Github](https://github.com/splitio/php-client) [Docs](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)
9088
* PHP thin-client [Github](https://github.com/splitio/php-thin-client) [Docs](https://help.split.io/hc/en-us/articles/18305128673933-PHP-Thin-Client-SDK)
9189
* Python [Github](https://github.com/splitio/python-client) [Docs](https://help.split.io/hc/en-us/articles/360020359652-Python-SDK)

webpack.common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = {
3030
],
3131
},
3232

33-
node: false, // Not include Node polyfills, https://webpack.js.org/configuration/node
33+
node: false, // Not include Node.js polyfills, https://webpack.js.org/configuration/node
3434
target: ['web', 'es5'], // target 'es5', since 'es2015' is the default in Webpack 5
3535

3636
externals: {

0 commit comments

Comments
 (0)