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
Closed
Babel preset: Make Platform inlining opt-in via inlinePlatform (default on via @react-native/metro-babel-transformer) (#57973)#57973robhogan wants to merge 1 commit into
@react-native/metro-babel-transformer) (#57973)#57973robhogan wants to merge 1 commit into
Conversation
|
@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
@react-native/metro-babel-transformer)@react-native/metro-babel-transformer) (#57973)
meta-codesync
Bot
force-pushed
the
export-D116281656
branch
from
August 17, 2026 10:02
538ef10 to
a36f915
Compare
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
|
This pull request has been merged in f63b2a1. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
react-native/babel-presetinlinesPlatform.OSandPlatform.select(...)whenever it is handed aplatform(since yesterday - #57848 ), but this is over-zealous -platformis a pre-existing transform option whose intent is to set the transform target. In some cases (eg, to allowPlatformmocking from tests), we don't wantPlatforminlining, even thoughplatformmay already be passed for other reasons.Gate the inlining behind a separate
inlinePlatformopt-in, resolved asoptions.inlinePlatform ?? babel.caller(...) ?? false, mirroring howplatformandunstable_transformProfileare 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 ababel.config.jsand so receives no preset options at all.Bundling is unaffected: Metro sets
inlinePlatformon every transform, soPlatformcontinues to be inlined throughreact-native/metro-babel-transformer.Changelog:
[General][Changed] -
Platform.OSandPlatform.select(...)inlining inreact-native/babel-presetnow requires theinlinePlatformoption in addition toplatformReviewed By: GijsWeterings
Differential Revision: D116281656