Skip to content

Navigation Menu

Sign in
Sign up

Preserve Platform.select initializer side effects - #1903

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

Preserve Platform.select initializer side effects #1903
mfkrause wants to merge 1 commit into
react:main from
mfkrause:fix/platform-select-side-effects

Conversation

@mfkrause

@mfkrause mfkrause commented Sep 4, 2026

Copy link
Copy Markdown

Summary

Metro 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 however.

This fix preserves both side effects by testing for purity.

Changelog:

 - **[Fix]**: Preserve side effects from discarded `Platform.select` property initializers

Test plan

Added a regression test, and ensured existing tests, linter and formatter pass.

@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
@mfkrause mfkrause changed the title (削除) fix(metro-transform-plugins): preserve Platform.select initializers (削除ここまで) (追記) Preserve Platform.select initializer side effects (追記ここまで) 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

vzaidman commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

why is the logic slightly different from react/react-native#58350 ?

meta-codesync Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

@vzaidman has imported this pull request. If you are a Meta employee, you can view this in D119065903.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

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

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /