Skip to content

fix(babel-preset): preserve Platform.select initializers - #58350

Open
mfkrause wants to merge 1 commit into
react:mainfrom
mfkrause:fix/platform-select-side-effects
Open

fix(babel-preset): preserve Platform.select initializers#58350
mfkrause wants to merge 1 commit into
react:mainfrom
mfkrause:fix/platform-select-side-effects

Conversation

@mfkrause

@mfkrause mfkrause commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary:

The React Native Babel preset replaces Platform.select({...}) with the selected property during production transforms. JavaScript evaluates every object property initializer before calling Platform.select, so this can silently remove side effects from non-selected properties.

For example:

Platform.select({
  ios: selected(),
  android: discarded(),
});

JavaScript would run both side effects, selected() and discarded(). The plugin's current behavior removes discarded on iOS however.

This fix preserves both side effects by testing for purity.

Changelog:

[GENERAL] [FIXED] - Preserve side effects from discarded Platform.select property initializers in the Babel preset.

Test Plan:

Added a regression test and ran existing tests, linter and formatter.

@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 Sep 4, 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 Sep 4, 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.

1 participant