Skip to content

Commit 599f6d5

Browse files
Merge pull request #190 from splitio/development
Release v1.11.1
2 parents d908180 + 21e44d1 commit 599f6d5

File tree

9 files changed

+208
-32
lines changed

9 files changed

+208
-32
lines changed

CHANGES.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
1.11.0 (January 16, 2023)
2-
- Added the new `SplitFactoryProvider` component as a replacement for the now deprecated `SplitFactory` component.
3-
The new component is a revised version of `SplitFactory`, addressing improper handling of the SDK initialization side-effects in the `componentDidMount` and `componentDidUpdate` methods (commit phase), causing some issues like memory leaks and the SDK not reinitializing when component props change (Related to issue #11 and #148).
4-
The `SplitFactoryProvider` component can be used as a drop-in replacement for `SplitFactory`. It utilizes the React Hooks API, that requires React 16.8.0 or later, and supports server-side rendering. See our documentation for more details (Related to issue #11 and #109).
1+
1.11.1 (March 26, 2024)
2+
- Bugfixing - Added tslib as an explicit dependency to avoid issues with some package managers that don't resolve it automatically as a transitive dependency from @splitsoftware/splitio-commons (Related to issue https://github.com/splitio/javascript-client/issues/795).
3+
4+
1.11.0 (January 16, 2024)
5+
- Added new `SplitFactoryProvider` component as a replacement for the now deprecated `SplitFactory` component.
6+
- Bugfixing: The new component is a revised version of `SplitFactory` that properly handles SDK side effects (i.e., factory creation and destruction) within the React component lifecycle,
7+
- resolving memory leak issues in React development mode, strict mode and server-side rendering (Related to issues #11 and #109),
8+
- and also ensuring that the SDK is updated if `config` or `factory` props change (Related to issues #11 and #148).
9+
- Notable changes when migrating from `SplitFactory` to `SplitFactoryProvider`:
10+
- `SplitFactoryProvider` utilizes the React Hooks API, requiring React 16.8.0 or later, while `SplitFactory` is compatible with React 16.3.0 or later.
11+
- When using the `config` prop with `SplitFactoryProvider`, the `factory` and `client` properties in `SplitContext` and the `manager` property in `useSplitManager` results are `null` in the first render, until the context is updated when some event is emitted on the SDK main client (ready, ready from cache, timeout, or update, depending on the configuration of the `updateOn<Event>` props of the component). This differs from the previous behavior where `factory`, `client`, and `manager` were immediately available.
12+
- Updating the `config` prop in `SplitFactoryProvider` reinitializes the SDK with the new configuration, while `SplitFactory` does not reinitialize the SDK. You should pass a reference to the configuration object (e.g., via a global variable, `useState`, or `useMemo`) rather than a new instance on each render, to avoid unnecessary reinitializations.
13+
- Updating the `factory` prop in `SplitFactoryProvider` replaces the current SDK instance, unlike `SplitFactory` where it is ignored.
514
- Updated internal code to remove a circular dependency and avoid warning messages with tools like PNPM (Related to issue #176).
615
- Updated @splitsoftware/splitio package to version 10.25.1 for vulnerability fixes.
716

MIGRATION-GUIDE.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
2+
# Migrating to get React SDK v1.11.0 improvements: Replacing the deprecated `SplitFactory` and `withSplitFactory` components
3+
4+
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.
5+
6+
We recommend migrating to the new `SplitFactoryProvider` component instead. This component is a revised version of `SplitFactory` that properly handles SDK side effects (i.e., factory creation and destruction) within the React component lifecycle. By migrating, you can benefit from a number of improvements:
7+
8+
- Resolution of memory leak issues in React development mode, strict mode, and server-side rendering.
9+
10+
- Updating the SDK when `config` or `factory` props change.
11+
12+
Notable changes to consider when migrating:
13+
- `SplitFactoryProvider` utilizes the React Hooks API, requiring React 16.8.0 or later, while `SplitFactory` is compatible with React 16.3.0 or later.
14+
15+
- When using the `config` prop with `SplitFactoryProvider`, the `factory` and `client` properties in `SplitContext` and the `manager` property in `useSplitManager` results are `null` in the first render, until the context is updated when some event is emitted on the SDK main client (ready, ready from cache, timeout, or update, depending on the configuration of the `updateOn<Event>` props of the component). This differs from the previous behavior where `factory`, `client`, and `manager` were immediately available. Nonetheless, it is not recommended to use the `client` and `factory` properties directly as better alternatives are available. For example, use the `useTrack` and `useSplitTreatments` hooks rather than the client's `track` and `getTreatments` methods.
16+
17+
- Updating the `config` prop in `SplitFactoryProvider` reinitializes the SDK with the new configuration, while `SplitFactory` does not reinitialize the SDK. You should pass a reference to the configuration object (e.g., via a global variable, `useState`, or `useMemo`) rather than a new instance on each render, to avoid unnecessary reinitializations.
18+
19+
- Updating the `factory` prop in `SplitFactoryProvider` replaces the current SDK instance, unlike `SplitFactory` where it is ignored.
20+
21+
To migrate your existing code, replace:
22+
23+
```javascript
24+
const MyApp = () => {
25+
return (
26+
<SplitFactory config={mySplitConfig}>
27+
<MyComponent />
28+
</SplitFactory>
29+
);
30+
};
31+
```
32+
33+
or
34+
35+
```javascript
36+
const MyApp = withSplitFactory(mySplitConfig)(MyComponent);
37+
```
38+
39+
with:
40+
41+
```javascript
42+
const MyApp = () => {
43+
return (
44+
<SplitFactoryProvider config={mySplitConfig}>
45+
<MyComponent />
46+
</SplitFactoryProvider>
47+
);
48+
};
49+
```
50+
51+
and consider that `factory`, `client` and `manager` properties might be `null` until the SDK has emitted some event:
52+
53+
```javascript
54+
const MyComponent = () => {
55+
// factoryFromContext === factory, clientFromContext === client, and they are null until some SDK event is emitted
56+
const { factory: factoryFromContext, client: clientFromContext } = useContext(SplitContext);
57+
const { factory, client } = useSplitClient();
58+
59+
// Example to evaluate all your flags when the SDK is ready and re-evaluate on SDK_UPDATE events
60+
const { manager } = useSplitManager();
61+
const FEATURE_FLAG_NAMES = manager ? manager.names() : [];
62+
const { treatments, isReady } = useSplitTreatments({ names: FEATURE_FLAG_NAMES, updateOnSdkUpdate: true }); // updateOnSdkReady is true by default
63+
64+
return isReady ?
65+
treatments['feature-flag-1'].treatment === 'on' ?
66+
<FeatureOn /> :
67+
<FeatureOff /> :
68+
<LoadingPage />
69+
}
70+
```
71+
72+
# Migrating to get React SDK v1.10.0 improvements: Replacing the deprecated `useClient`, `useTreatments`, and `useManager` hooks
73+
74+
Starting from React SDK v1.10.0, the `useSplitClient`, `useSplitTreatments`, and `useSplitManager` hooks are available and can replace the older `useClient`, `useTreatments`, and `useManager` hooks respectively. The deprecated hooks will continue working, until they are removed in a future major release.
75+
76+
We recommend migrating to the new versions `useSplitClient`, `useSplitTreatments` and `useSplitManager` respectively, which provide a more flexible API:
77+
78+
- They accept an options object as parameter, instead of a list of parameters as their deprecated counterparts. The options object can contain the same parameters as the old hooks, plus some extra optional parameters: `updateOnSdkReady`, `updateOnSdkReadyFromCache`, `updateOnSdkTimedout`, and `updateOnSdkUpdate`, which control when the hook updates the component. For example, you can set `updateOnSdkUpdate` to `true`, which is `false` by default, to update the component when an `SDK_UPDATE` event is emitted. This is useful when you want to avoid unnecessary re-renders of your components.
79+
80+
- They return an object containing the SDK status properties. These properties are described in the ['Subscribe to events and changes' section](https://help.split.io/hc/en-us/articles/360038825091-React-SDK#subscribe-to-events-and-changes) and enable conditional rendering of components based on the SDK status, eliminating the need to access the Split context or use the client's `ready` promise or event listeners. For example, you can show a loading spinner until the SDK is ready, and use the `treatments` result to render the variants of your app once the SDK is ready.
81+
82+
The usage of the new hooks is shown below:
83+
84+
```js
85+
const { client, isReady, isReadyFromCache, hasTimedout, lastUpdate } = useSplitClient({ splitKey: userId, updateOnSdkUpdate: true });
86+
const { treatments, isReady, isReadyFromCache, hasTimedout, lastUpdate } = useSplitTreatments({ names: ['feature-flag-1'], updateOnSdkTimedout: false });
87+
const { manager, isReady, isReadyFromCache, hasTimedout, lastUpdate } = useSplitManager();
88+
```
89+
90+
91+
92+
To migrate your existing code, replace:
93+
94+
```javascript
95+
const client = useClient(optionalSplitKey, optionalTrafficType, optionalAttributes);
96+
const treatments = useTreatments(featureFlagNames, optionalAttributes, optionalSplitKey);
97+
const manager = useManager();
98+
```
99+
100+
with:
101+
102+
```javascript
103+
const { client } = useSplitClient({ splitKey: optionalSplitKey, trafficType: optionalTrafficType, attributes: optionalAttributes });
104+
const { treatments } = useSplitTreatments({ names: featureFlagNames, attributes: optionalAttributes, splitKey: optionalSplitKey });
105+
const { manager } = useSplitManager();
106+
```
107+
108+
and use the status properties to conditionally render your components. For example, use the following code:
109+
110+
```javascript
111+
const MyComponent = ({ userId }) => {
112+
113+
const { treatments, isReady } = useSplitTreatments({ names: [FEATURE_X], splitKey: userId })
114+
115+
return isReady ?
116+
treatments[FEATURE_X].treatment === 'on' ?
117+
<FeatureOn /> :
118+
<FeatureOff /> :
119+
<LoadingPage />
120+
}
121+
```
122+
123+
instead of:
124+
125+
```javascript
126+
const MyComponent = ({ userId }) => {
127+
128+
const [sdkIsReady, setSdkIsReady] = useState(false);
129+
const client = useClient(userId);
130+
const treatments = useTreatments([FEATURE_X], undefined, userId);
131+
132+
useEffect(() => {
133+
if (client) client.ready().then(() => setSdkIsReady(true));
134+
}, [client]);
135+
136+
return isReady ?
137+
treatments[FEATURE_X].treatment === 'on' ?
138+
<FeatureOn /> :
139+
<FeatureOff /> :
140+
<LoadingPage />
141+
}
142+
```

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ Split has built and maintains SDKs for:
7979
* .NET [Github](https://github.com/splitio/dotnet-client) [Docs](https://help.split.io/hc/en-us/articles/360020240172--NET-SDK)
8080
* Android [Github](https://github.com/splitio/android-client) [Docs](https://help.split.io/hc/en-us/articles/360020343291-Android-SDK)
8181
* Angular [Github](https://github.com/splitio/angular-sdk-plugin) [Docs](https://help.split.io/hc/en-us/articles/6495326064397-Angular-utilities)
82+
* Flutter [Github](https://github.com/splitio/flutter-sdk-plugin) [Docs](https://help.split.io/hc/en-us/articles/8096158017165-Flutter-plugin)
8283
* GO [Github](https://github.com/splitio/go-client) [Docs](https://help.split.io/hc/en-us/articles/360020093652-Go-SDK)
8384
* iOS [Github](https://github.com/splitio/ios-client) [Docs](https://help.split.io/hc/en-us/articles/360020401491-iOS-SDK)
8485
* Java [Github](https://github.com/splitio/java-client) [Docs](https://help.split.io/hc/en-us/articles/360020405151-Java-SDK)
8586
* JavaScript [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK)
8687
* JavaScript for Browser [Github](https://github.com/splitio/javascript-browser-client) [Docs](https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK)
8788
* Node [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
8889
* PHP [Github](https://github.com/splitio/php-client) [Docs](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)
90+
* 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)
8991
* Python [Github](https://github.com/splitio/python-client) [Docs](https://help.split.io/hc/en-us/articles/360020359652-Python-SDK)
9092
* React [Github](https://github.com/splitio/react-client) [Docs](https://help.split.io/hc/en-us/articles/360038825091-React-SDK)
9193
* React Native [Github](https://github.com/splitio/react-native-client) [Docs](https://help.split.io/hc/en-us/articles/4406066357901-React-Native-SDK)

package-lock.json

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

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "@splitsoftware/splitio-react",
3-
"version": "1.11.0",
3+
"version": "1.11.1",
44
"description": "A React library to easily integrate and use Split JS SDK",
55
"main": "lib/index.js",
66
"module": "es/index.js",
77
"types": "types/index.d.ts",
88
"files": [
99
"README.md",
1010
"CONTRIBUTORS-GUIDE.md",
11+
"MIGRATION-GUIDE.md",
1112
"LICENSE",
1213
"CHANGES.txt",
1314
"src",
@@ -62,9 +63,10 @@
6263
},
6364
"homepage": "https://github.com/splitio/react-client#readme",
6465
"dependencies": {
65-
"@splitsoftware/splitio": "10.25.1",
66+
"@splitsoftware/splitio": "10.25.2",
6667
"memoize-one": "^5.1.1",
67-
"shallowequal": "^1.1.0"
68+
"shallowequal": "^1.1.0",
69+
"tslib": "^2.3.1"
6870
},
6971
"devDependencies": {
7072
"@testing-library/jest-dom": "^5.16.5",

src/SplitFactory.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@ import { DEFAULT_UPDATE_OPTIONS } from './useSplitClient';
1414
* The underlying SDK factory and client is set on the constructor, and cannot be changed during the component lifecycle,
1515
* even if the component is updated with a different config or factory prop.
1616
*
17-
* @deprecated Replace with the new `SplitFactoryProvider` component.
18-
* `SplitFactoryProvider` is a drop-in replacement that properly handles side effects (factory creation and destruction) within the React component lifecycle, avoiding issues with factory recreation and memory leaks.
19-
* Note: There is a subtle breaking change in `SplitFactoryProvider`. When using the `config` prop, `factory` and `client` properties in the context are `null` in the first render, until the context is updated when some event is emitted on
20-
* the SDK main client (ready, ready from cache, timeout or update depending on the configuration of the `updateOnXXX` props of the component). This differs from the previous behavior where `factory` and `client` were immediately available.
17+
* @deprecated `SplitFactory` will be removed in a future major release. We recommend replacing it with the new `SplitFactoryProvider` component.
18+
*
19+
* `SplitFactoryProvider` is a revised version of `SplitFactory` that properly handles SDK side effects (i.e., factory creation and destruction) within the React component lifecycle,
20+
* resolving memory leak issues in React development mode, strict mode and server-side rendering, and also ensuring that the SDK is updated if `config` or `factory` props change.
21+
*
22+
* Notable changes to consider when migrating:
23+
* - `SplitFactoryProvider` utilizes the React Hooks API, requiring React 16.8.0 or later, while `SplitFactory` is compatible with React 16.3.0 or later.
24+
* - When using the `config` prop with `SplitFactoryProvider`, the `factory` and `client` properties in `SplitContext` and the `manager` property in `useSplitManager` results
25+
* are `null` in the first render, until the context is updated when some event is emitted on the SDK main client (ready, ready from cache, timeout, or update, depending on
26+
* the configuration of the `updateOn<Event>` props of the component). This differs from the previous behavior where `factory`, `client`, and `manager` were immediately available.
27+
* - Updating the `config` prop in `SplitFactoryProvider` reinitializes the SDK with the new configuration, while `SplitFactory` does not reinitialize the SDK. You should pass a
28+
* reference to the configuration object (e.g., via a global variable, `useState`, or `useMemo`) rather than a new instance on each render, to avoid unnecessary reinitializations.
29+
* - Updating the `factory` prop in `SplitFactoryProvider` replaces the current SDK instance, unlike `SplitFactory` where it is ignored.
2130
*
2231
* @see {@link https://help.split.io/hc/en-us/articles/360038825091-React-SDK#2-instantiate-the-sdk-and-create-a-new-split-client}
2332
*/

0 commit comments

Comments
 (0)