-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Is this a support request?
No
Describe the bug
This is more a bug that comes as a result of using the React Native SDK, but manifests as a result of differences in implementation between the Android and iOS SDKs, so it seems like this is a better place to raise the issue. If this does belong in the RN SDK issues instead let me know and I can re-open there instead.
As surfaced in launchdarkly/react-native-client-sdk#121, we discovered that LD's mobile SDKs don't officially support hot reload. However, we had discovered a workaround at the time whereby we could always close the client first, then call configure again, which would bypass the "already initialized" issue and allow us to (seemingly) use the SDK as one would expect, even in cases of hot reloads.
However, it turned out that this only worked for iOS, and not Android. A bit of digging around into the issue showed that:
close()in iOS does causeisInitialized()to return false, while in Android it does notclose()in iOS causesisInitialized()to reject, while in Android is resolves with a truesetOnline()DOES causeisInitialized()to return false in both, but it doesn't matter sinceconfigure()relies on a reject
I suspect this is due to differences in how the two native SDKs are implemented, rather than how the RN SDK is implemented.
To reproduce
- Look at the repro in "LaunchDarkly SDK already initialized" before configure has been called react-native-client-sdk#121 (which surfaces when you do a hot reload)
- Now, instead of using the snippet in step 4 there, do the following and see how initialized returns false now in iOS (after a hot reload) as a result of the preliminary
client.close():
const App: () => Node = () => {
let client = new LDClient();
client.close().isInitialized().then((isInitialized) => {
console.log('initialized? ', isInitialized);
if (!isInitialized) {
client
.configure(
{mobileKey: '<insert_key>'},
{key: 'user_key'},
)
.then(() => console.log('success'));
}
});
- Now observe how this does not work in Android
Expected behavior
While this is an undocumented/unofficial workaround/use case, I'd expect the two SDKs to behave similarly. But parity aside, it seems wrong that closing the client doesn't reset/reject the initialization state correctly in Android
SDK version
"dependencies": {
"launchdarkly-react-native-client-sdk": "^6.1.0",
"react": "17.0.2",
"react-native": "0.67.3"
},
Language version, developer tools
React Native, Flipper, yarn
OS/platform
MacOS 12.1
Additional context
I've previously reached out to customer support around this, and was told there were not plans to bring the two SDKs to parity, and that they'd put in a feature request. I didn't see anything in Github so opening it up here for tracking.