Skip to content

Conversation

CalhamJNorthway
Copy link

@CalhamJNorthway CalhamJNorthway commented Sep 10, 2025

The purpose of this PR is to fix a crash I found yesterday caused by an accessor that is undefined when newer versions of react native have Fabric enabled.

Our Build Setup:
react-native: v0.80.0
@launchdarkly/react-native-client-sdk: v10.1.5

Requirements

  • add null coalescing operation to use getConstants to prevent undefined settings object
  • still default to old accessor if not undefined

Related issues
I've not seen any related issues yet regarding your repo, though I did find this one Stack Overflow post.

Describe the solution you've provided
The solution I've provided is to use a null coalescing check to fallback to the new getConstants method on native modules if the settings object is undefined.

Describe alternatives you've considered
I searched to see if there are preferred alternatives and did not come up with any other solutions. I am open to feedback on that though :)

- add check for undefined settings constant
- add null coalescing operation to use getConstants to prevent undefined settings object
@CalhamJNorthway CalhamJNorthway requested a review from a team as a code owner September 10, 2025 20:11
export default Platform.select({
ios: getAppleLocale(),
android: NativeModules.I18nManager?.localeIdentifier,
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Platform Select Returns Undefined, Calls iOS Code Unnecessarily

The Platform.select implementation now returns undefined for non-iOS/Android platforms, removing the previous I18nManager?.localeIdentifier fallback. Additionally, getAppleLocale() is called immediately on module load for all platforms, causing iOS-specific native module code to execute unnecessarily.

Fix in Cursor Fix in Web

@kinyoklion
Copy link
Member

@CalhamJNorthway Thank you for the PR!

What was the crash you are seeing? While I think that we need an update to reliably be accessing the locale, I don't see anything that was doing anything other than forwarding along the undefined value. Settings was undefined, but the app locale as already being conditionally accessed from it.

NativeModules.SettingsManager?.settings?.AppleLocale

Though there was a previous version where it looked like this:
NativeModules.SettingsManager?.settings.AppleLocale

Which would have crashed.

Thank you,
Ryan

@CalhamJNorthway
Copy link
Author

CalhamJNorthway commented Sep 10, 2025

@CalhamJNorthway Thank you for the PR!

What was the crash you are seeing? While I think that we need an update to reliably be accessing the locale, I don't see anything that was doing anything other than forwarding along the undefined value. Settings was undefined, but the app locale as already being conditionally accessed from it.

NativeModules.SettingsManager?.settings?.AppleLocale

Though there was a previous version where it looked like this: NativeModules.SettingsManager?.settings.AppleLocale

Which would have crashed.

Thank you, Ryan

Hey @kinyoklion, thanks for the prompt reply. I can add a little more detail, the issue was actually with the launch darkly client not instantiating correctly when the locale was undefined. You end up getting an error

Error initializing LaunchDarkly: TypeError: Cannot read property 'ldApplication' of undefined

Which after some further digging, I'm assuming was caused by the error below bubbling up to a higher error boundary

Error initializing LaunchDarkly: TypeError: Cannot read property 'AppleLocale' of undefined

Also for posterity, I have validated this fix with a node module patch on our application.
If you would like me to reproduce it with some screenshots I can do that tomorrow and post them here as a reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants