Skip to content

Babel preset: Make Platform inlining opt-in via inlinePlatform (default on via @react-native/metro-babel-transformer) (#57973) - #57973

Closed
robhogan wants to merge 1 commit into
mainfrom
export-D116281656
Closed

Babel preset: Make Platform inlining opt-in via inlinePlatform (default on via @react-native/metro-babel-transformer) (#57973)#57973
robhogan wants to merge 1 commit into
mainfrom
export-D116281656

Conversation

@robhogan

@robhogan robhogan commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Summary:

react-native/babel-preset inlines Platform.OS and Platform.select(...) whenever it is handed a platform (since yesterday - #57848 ), but this is over-zealous - platform is a pre-existing transform option whose intent is to set the transform target. In some cases (eg, to allow Platform mocking from tests), we don't want Platform inlining, even though platform may already be passed for other reasons.

Gate the inlining behind a separate inlinePlatform opt-in, resolved as options.inlinePlatform ?? babel.caller(...) ?? false, mirroring how platform and unstable_transformProfile are already resolved. Metro already models this as a distinct transform option, so both Babel transformers pass it straight through. The caller channel covers the case where the preset is named in a babel.config.js and so receives no preset options at all.

Bundling is unaffected: Metro sets inlinePlatform on every transform, so Platform continues to be inlined through react-native/metro-babel-transformer.

Changelog:
[General][Changed] - Platform.OS and Platform.select(...) inlining in react-native/babel-preset now requires the inlinePlatform option in addition to platform

Reviewed By: GijsWeterings

Differential Revision: D116281656

@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 17, 2026
@meta-codesync

meta-codesync Bot commented Aug 17, 2026

Copy link
Copy Markdown

@robhogan has exported this pull request. If you are a Meta employee, you can view the originating Diff in D116281656.

…lt on via `@react-native/metro-babel-transformer`) (#57973)

Summary:

`react-native/babel-preset` inlines `Platform.OS` and `Platform.select(...)` whenever it is handed a `platform` (since yesterday - #57848 ), but this is over-zealous - `platform` is a pre-existing transform option whose intent is to set the transform target. In some cases (eg, to allow `Platform` mocking from tests), we don't want `Platform` inlining, even though `platform` may already be passed for other reasons.

Gate the inlining behind a separate `inlinePlatform` opt-in, resolved as `options.inlinePlatform ?? babel.caller(...) ?? false`, mirroring how `platform` and `unstable_transformProfile` are already resolved. Metro already models this as a distinct transform option, so both Babel transformers pass it straight through. The caller channel covers the case where the preset is named in a `babel.config.js` and so receives no preset options at all.

Bundling is unaffected: Metro sets `inlinePlatform` on every transform, so `Platform` continues to be inlined through `react-native/metro-babel-transformer`.

Changelog:
[General][Changed] - `Platform.OS` and `Platform.select(...)` inlining in `react-native/babel-preset` now requires the `inlinePlatform` option in addition to `platform`

Reviewed By: GijsWeterings

Differential Revision: D116281656
@meta-codesync meta-codesync Bot changed the title Babel preset: Make Platform inlining opt-in via inlinePlatform (default on via @react-native/metro-babel-transformer) Babel preset: Make Platform inlining opt-in via inlinePlatform (default on via @react-native/metro-babel-transformer) (#57973) Aug 17, 2026
@meta-codesync
meta-codesync Bot force-pushed the export-D116281656 branch from 538ef10 to a36f915 Compare August 17, 2026 10:02
meta-codesync Bot pushed a commit to react/metro that referenced this pull request Aug 17, 2026
…lt on via `@react-native/metro-babel-transformer`)

Summary:
X-link: react/react-native#57973

`react-native/babel-preset` inlines `Platform.OS` and `Platform.select(...)` whenever it is handed a `platform` (since yesterday - react/react-native#57848 ), but this is over-zealous - `platform` is a pre-existing transform option whose intent is to set the transform target. In some cases (eg, to allow `Platform` mocking from tests), we don't want `Platform` inlining, even though `platform` may already be passed for other reasons.

Gate the inlining behind a separate `inlinePlatform` opt-in, resolved as `options.inlinePlatform ?? babel.caller(...) ?? false`, mirroring how `platform` and `unstable_transformProfile` are already resolved. Metro already models this as a distinct transform option, so both Babel transformers pass it straight through. The caller channel covers the case where the preset is named in a `babel.config.js` and so receives no preset options at all.

Bundling is unaffected: Metro sets `inlinePlatform` on every transform, so `Platform` continues to be inlined through `react-native/metro-babel-transformer`.

Changelog:
[General][Changed] - `Platform.OS` and `Platform.select(...)` inlining in `react-native/babel-preset` now requires the `inlinePlatform` option in addition to `platform`

Reviewed By: GijsWeterings

Differential Revision: D116281656

fbshipit-source-id: 0230cd74f38661862396391da62cf81b34773b85
@meta-codesync meta-codesync Bot closed this in f63b2a1 Aug 17, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Aug 17, 2026
@meta-codesync

meta-codesync Bot commented Aug 17, 2026

Copy link
Copy Markdown

This pull request has been merged in f63b2a1.

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. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant