-
Notifications
You must be signed in to change notification settings - Fork 12
Add MIGRATION-GUIDE.md file #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d908180
Merge pull request #184 from splitio/development
EmilianoSanchez 2296052
Update CHANGES file and comments to explain breaking changes when mig…
EmilianoSanchez c1803ca
Update comment regarding factory and config props in SplitFactoryProv…
EmilianoSanchez 6105b3f
Nico's feedback: 'Notable changes' rather than 'Breaking changes'
EmilianoSanchez 11e01ae
Team's feedback: add MIGRATION-GUIDE.md file
EmilianoSanchez 4d88095
Team's feedback: add MIGRATION-GUIDE.md file
EmilianoSanchez 50b5028
Polishing
EmilianoSanchez 40fdfe1
Lena's feedback
EmilianoSanchez af8066d
Rollback header links (not working as expected)
EmilianoSanchez 2bbe2ca
Lena's feedback
EmilianoSanchez ceac3a7
Add migration example for SplitFactoryProvider
EmilianoSanchez 06aedbc
Merge branch 'migration-guide' into breaking-changes-explanation
EmilianoSanchez eee6e11
Polishing
EmilianoSanchez f0b6978
Add comment regarding manager property
EmilianoSanchez 8be63a9
Merge branch 'migration-guide' into breaking-changes-explanation
EmilianoSanchez d28e3eb
Polishing
EmilianoSanchez fb36783
Update MIGRATION-GUIDE.md
EmilianoSanchez ed85e6b
Merge branch 'breaking-changes-explanation' into migration-guide
EmilianoSanchez d8a77bf
Formatting
EmilianoSanchez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
|
|
||
| # Migrating to get React SDK v1.11.0 improvements: Replacing the deprecated `SplitFactory` and `withSplitFactory` components | ||
|
|
||
| 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. | ||
|
|
||
| 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: | ||
|
|
||
| - Resolution of memory leak issues in React development mode, strict mode, and server-side rendering. | ||
|
|
||
| - Updating the SDK when `config` or `factory` props change. | ||
|
|
||
| Notable changes to consider when migrating: | ||
| - `SplitFactoryProvider` utilizes the React Hooks API, requiring React 16.8.0 or later, while `SplitFactory` is compatible with React 16.3.0 or later. | ||
|
|
||
| - 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. | ||
|
|
||
| - 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. | ||
|
|
||
| - Updating the `factory` prop in `SplitFactoryProvider` replaces the current SDK instance, unlike `SplitFactory` where it is ignored. | ||
|
|
||
| To migrate your existing code, replace: | ||
|
|
||
| ```javascript | ||
| const MyApp = () => { | ||
| return ( | ||
| <SplitFactory config={mySplitConfig}> | ||
| <MyComponent /> | ||
| </SplitFactory> | ||
| ); | ||
| }; | ||
| ``` | ||
|
|
||
| or | ||
|
|
||
| ```javascript | ||
| const MyApp = withSplitFactory(mySplitConfig)(MyComponent); | ||
| ``` | ||
|
|
||
| with: | ||
|
|
||
| ```javascript | ||
| const MyApp = () => { | ||
| return ( | ||
| <SplitFactoryProvider config={mySplitConfig}> | ||
| <MyComponent /> | ||
| </SplitFactoryProvider> | ||
| ); | ||
| }; | ||
| ``` | ||
|
|
||
| and consider that `factory`, `client` and `manager` properties might be `null` until the SDK has emitted some event: | ||
|
|
||
| ```javascript | ||
| const MyComponent = () => { | ||
| // factoryFromContext === factory, clientFromContext === client, and they are null until some SDK event is emitted | ||
| const { factory: factoryFromContext, client: clientFromContext } = useContext(SplitContext); | ||
| const { factory, client } = useSplitClient(); | ||
|
|
||
| // Example to evaluate all your flags when the SDK is ready and re-evaluate on SDK_UPDATE events | ||
| const { manager } = useSplitManager(); | ||
| const FEATURE_FLAG_NAMES = manager ? manager.names() : []; | ||
| const { treatments, isReady } = useSplitTreatments({ names: FEATURE_FLAG_NAMES, updateOnSdkUpdate: true }); // updateOnSdkReady is true by default | ||
|
|
||
| return isReady ? | ||
| treatments['feature-flag-1'].treatment === 'on' ? | ||
| <FeatureOn /> : | ||
| <FeatureOff /> : | ||
| <LoadingPage /> | ||
| } | ||
| ``` | ||
|
|
||
| # Migrating to get React SDK v1.10.0 improvements: Replacing the deprecated `useClient`, `useTreatments`, and `useManager` hooks | ||
|
|
||
| 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. | ||
|
|
||
| We recommend migrating to the new versions `useSplitClient`, `useSplitTreatments` and `useSplitManager` respectively, which provide a more flexible API: | ||
|
|
||
| - 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. | ||
|
|
||
| - 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. | ||
|
|
||
| The usage of the new hooks is shown below: | ||
|
|
||
|
EmilianoSanchez marked this conversation as resolved.
|
||
| ```js | ||
| const { client, isReady, isReadyFromCache, hasTimedout, lastUpdate } = useSplitClient({ splitKey: userId, updateOnSdkUpdate: true }); | ||
| const { treatments, isReady, isReadyFromCache, hasTimedout, lastUpdate } = useSplitTreatments({ names: ['feature-flag-1'], updateOnSdkTimedout: false }); | ||
| const { manager, isReady, isReadyFromCache, hasTimedout, lastUpdate } = useSplitManager(); | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
| To migrate your existing code, replace: | ||
|
|
||
| ```javascript | ||
| const client = useClient(optionalSplitKey, optionalTrafficType, optionalAttributes); | ||
| const treatments = useTreatments(featureFlagNames, optionalAttributes, optionalSplitKey); | ||
| const manager = useManager(); | ||
| ``` | ||
|
|
||
| with: | ||
|
|
||
| ```javascript | ||
| const { client } = useSplitClient({ splitKey: optionalSplitKey, trafficType: optionalTrafficType, attributes: optionalAttributes }); | ||
| const { treatments } = useSplitTreatments({ names: featureFlagNames, attributes: optionalAttributes, splitKey: optionalSplitKey }); | ||
| const { manager } = useSplitManager(); | ||
| ``` | ||
|
|
||
| and use the status properties to conditionally render your components. For example, use the following code: | ||
|
|
||
| ```javascript | ||
| const MyComponent = ({ userId }) => { | ||
|
|
||
| const { treatments, isReady } = useSplitTreatments({ names: [FEATURE_X], splitKey: userId }) | ||
|
|
||
| return isReady ? | ||
| treatments[FEATURE_X].treatment === 'on' ? | ||
| <FeatureOn /> : | ||
| <FeatureOff /> : | ||
| <LoadingPage /> | ||
| } | ||
| ``` | ||
|
|
||
| instead of: | ||
|
|
||
| ```javascript | ||
| const MyComponent = ({ userId }) => { | ||
|
|
||
| const [sdkIsReady, setSdkIsReady] = useState(false); | ||
| const client = useClient(userId); | ||
| const treatments = useTreatments([FEATURE_X], undefined, userId); | ||
|
|
||
| useEffect(() => { | ||
| if (client) client.ready().then(() => setSdkIsReady(true)); | ||
| }, [client]); | ||
|
|
||
| return isReady ? | ||
| treatments[FEATURE_X].treatment === 'on' ? | ||
| <FeatureOn /> : | ||
| <FeatureOff /> : | ||
| <LoadingPage /> | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.