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 :)


Note

Fixes iOS locale detection to avoid crashes on Fabric-enabled React Native by falling back to SettingsManager.getConstants; also adds a lint:fix script.

  • SDK (React Native)
    • Locale detection (src/platform/locale.ts): Use Platform.select and fall back to SettingsManager.getConstants()?.settings for iOS AppleLocale; keep Android using I18nManager.localeIdentifier.
  • Tooling
    • Add lint:fix script in package.json.

Written by Cursor Bugbot for commit 3d8605d. This will update automatically on new commits. Configure here.

- 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
@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!

Copy link
Contributor

@joker23 joker23 left a comment

Choose a reason for hiding this comment

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

Thanks @CalhamJNorthway for the PR! Sorry for the delay in response, but I think this PR would be ready to merge after addressing my comments.

ios: () => {
const settings =
NativeModules.SettingsManager?.settings ??
NativeModules.SettingsManager?.getConstants()?.settings;
Copy link

Choose a reason for hiding this comment

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

Bug: Incorrect accessor path for getConstants() in Fabric

The fallback accessor NativeModules.SettingsManager?.getConstants()?.settings likely has an incorrect property path. In React Native's new Fabric architecture, getConstants() typically returns constants directly at the top level (e.g., {AppleLocale: 'en_US'}), not nested under a settings property. This means getConstants()?.settings would return undefined, causing AppleLocale to never be found even when available through getConstants(). The accessor likely needs to be getConstants()?.AppleLocale or getConstants() should replace the entire settings variable.

Fix in Cursor Fix in Web

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.

3 participants