splitio / react-client

React JS SDK client for Split Software
https://split.io
Other
28 stars 12 forks source link

React SDK doesn't load in React 18's StrictMode #221

Open TatarczykAVitesse opened 1 day ago

TatarczykAVitesse commented 1 day ago

Hello

I've been trying to integrate Split in my app but the features would never load (isReady property is never set to true) and it turned out it's because in the development mode I'm using React's StrictMode. As soon as I moved the SplitFactoryProvider outside of it, everything starts to work properly.

I prepared a reproduction repo based on the React's example app https://github.com/TatarczykAVitesse/react-typescript-sdk-examples

Interestingly, as soon as I downgrade from version 2 to version 1 of @splitsoftware/splitio-react, it starts to work with no further changes

EmilianoSanchez commented 1 day ago

Hi @TatarczykAVitesse,

We will include a fix for this in the next release. The fix has already been developed here: https://github.com/splitio/react-client/pull/217

In the meantime, you can try a release candidate that includes a fix: "@splitsoftware/splitio-react": "^2.0.1-rc.0", or consider passing the factory instance rather than the config object to the SplitFactoryProvider:

import {SplitFactoryProvider, SplitFactory} from '@splitsoftware/splitio-react';
...

const sdkFactory = SplitFactory(sdkConfig);

root.render(
  <StrictMode>
    <SplitFactoryProvider factory={sdkFactory}>
      <App />
    </SplitFactoryProvider>
  </StrictMode>
);

I will keep the issue open, let you know, and then close it when the release is done :)

Thanks for sharing!