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

Low Risk
Small, localized change to iOS locale detection plus an added lint script; low blast radius, with only minor risk of behavior differences in locale resolution on iOS.

Overview
Fixes iOS locale detection in the React Native SDK to avoid crashes on Fabric-enabled apps by falling back from SettingsManager.settings to SettingsManager.getConstants()?.settings when reading AppleLocale.

Adds a lint:fix script to the React Native package to run ESLint with --fix.

Written by Cursor Bugbot for commit 0ee1355. 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

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

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.

Missing optional chaining on getConstants function call

High Severity

The code NativeModules.SettingsManager?.getConstants()?.settings will throw a TypeError if SettingsManager exists but getConstants is not a function. The optional chain before getConstants() only guards against SettingsManager being nullish, not getConstants being undefined. In older React Native versions without Fabric/TurboModules, getConstants may not exist on SettingsManager. The fix is to use getConstants?.() to safely handle the case where the method doesn't exist.

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