Skip to content

Inline the last duplicate Platform.select key - #58249

Open
OskarEichler wants to merge 1 commit into
react:mainfrom
OskarEichler:codex/fix-inline-platform-duplicate-keys
Open

Inline the last duplicate Platform.select key#58249
OskarEichler wants to merge 1 commit into
react:mainfrom
OskarEichler:codex/fix-inline-platform-duplicate-keys

Conversation

@OskarEichler

Copy link
Copy Markdown
Contributor

Summary:

The React Native Babel preset statically replaces Platform.select({...}) for the target platform. Its property scan currently stops at the first matching key, while JavaScript object-literal evaluation keeps the last duplicate definition. For example, Platform.select({ios: 1, ios: 2}) runs as 2 but the preset compiles it to 1.

Scan the already-validated static properties from the end so compiled output matches runtime semantics while preserving O(n), allocation-free lookup. Metro has a parallel transform that can run first; companion Metro PR #1889 applies the same correction so output remains transform-order independent.

Changelog:

[GENERAL] [FIXED] - Inline the last duplicate key from static Platform.select object literals.

Test Plan:

  • Added a focused preset regression; pristine main emits const value=1, while the fix emits const value=2.
  • Full preset Jest passes: 4/4 suites, 111/111 tests, 16 snapshots.
  • Fresh Flow check reports 0 errors.
  • Targeted no-ignore ESLint, Prettier, and git diff --check pass.

No behavior changes for object literals without duplicate static keys; no UI change.

@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 Aug 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 Aug 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.

2 participants