Skip to content

fix: lazily evaluate Platform in Settings to resolve circular dependency startup crash (#56967)#57006

Open
siddeshgawande wants to merge 1 commit into
facebook:mainfrom
siddeshgawande:fix/settings-circular-dep-56967
Open

fix: lazily evaluate Platform in Settings to resolve circular dependency startup crash (#56967)#57006
siddeshgawande wants to merge 1 commit into
facebook:mainfrom
siddeshgawande:fix/settings-circular-dep-56967

Conversation

@siddeshgawande
Copy link
Copy Markdown

Closes #56967

Summary:

This PR resolves a fatal TypeError: Cannot read property 'OS' of undefined startup crash occurring due to a circular dependency loop between Settings.js and Platform.js.

Previously, Settings.js evaluated Platform.OS immediately at module load-time. If another module required Settings before Platform finished initializing its export graph, Platform resolved to undefined and crashed the environment.

This change replaces top-level platform execution with a lazy proxy initializer (getSettings()). Platform.OS and the underlying platform implementation are now only required and resolved at runtime when a consumer invokes a method for the first time, safely eliminating the race condition.

Changelog:

[GENERAL] [FIXED] - Lazily evaluate Platform in Settings to prevent circular dependency startup crashes

Test Plan:

I added a dedicated test suite to Settings-test.js verifying that Settings can be successfully imported even if Platform is undefined during initial module load execution.

Ran the local Jest tests for the module, and all checks pass successfully:

yarn jest packages/react-native/Libraries/Settings/__tests__/Settings-test.js

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 30, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read property 'OS' of undefined in Libraries/Settings/Settings.js due to circular dependency on startup

1 participant