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

Use a Fabric-safe iOS locale retrieval via SettingsManager.settings ?? SettingsManager.getConstants()?.settings, and add a lint:fix script.

  • Locale handling (packages/sdk/react-native/src/platform/locale.ts)
    • Use Platform.select with iOS path resolving AppleLocale from SettingsManager.settings ?? SettingsManager.getConstants()?.settings; default to I18nManager.localeIdentifier.
    • Export the evaluated value via localeIdentifier().
  • Tooling (packages/sdk/react-native/package.json)
    • Add lint:fix script.

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

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