getCacheKey only hashes package contents when the version ends in -main;
published releases short-circuit to the version string. The test asserted
only the main-build property, so it failed on every release branch.
Assert the correct property for each case.
Summary:
The source-optimized preset enables native component codegen only when `codegenNativeComponent` is immediately followed by `<`. Valid Flow syntax permits comments or whitespace before the type arguments, so `codegenNativeComponent /* comment */ <NativeProps>(...)` bypasses codegen and emits an ordinary runtime call instead of the generated `__INTERNAL_VIEW_CONFIG` produced by the full preset path.
Use the stable `codegenNativeComponent` identifier token as the cheap source prefilter while retaining the existing null/undefined full-scan path. Formatting no longer changes build output; false-positive tokens only enable the codegen visitor, which remains a no-op without a matching call.
## Changelog:
[GENERAL] [FIXED] - Run native component codegen when Flow type arguments are separated by trivia.
Pull Request resolved: https://github.com/react/react-native/pull/58257
Test Plan:
- Added a valid Flow native-component spec containing a comment before `<NativeProps>`.
- Exact optimized baseline emits the ordinary call without `__INTERNAL_VIEW_CONFIG`; the fixed transform generates the static view config.
- 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 public API or breaking behavior change; optimized and full preset paths now agree for valid formatting.
Reviewed By: GijsWeterings
Differential Revision: D118266389
Pulled By: javache
fbshipit-source-id: 0b4279eed9f831e1e8f4669bd522645023dfdeac
Summary:
`customTransformOptions.unstable_preserveClassPrivate` currently disables private-field and private-method transforms for every profile. With `hermes-legacy`, the preset still lowers the surrounding class syntax, and Babel then aborts because its class transform requires the private transforms.
Only preserve private syntax when the selected profile also preserves class syntax. Stable and canary Hermes profiles keep their existing experimental behavior; legacy profiles continue lowering private fields and methods together with classes instead of crashing.
## Changelog:
[GENERAL] [FIXED] - Keep private class transforms enabled for profiles that lower classes.
Pull Request resolved: https://github.com/react/react-native/pull/58253
Test Plan:
- Added a focused `hermes-legacy` regression containing both a private field and private method with the preservation option enabled.
- Exact baseline throws Babel's private-method transform error; the fixed preset compiles and emits the normal private-field helpers.
- 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 breaking change: stable/canary preservation is unchanged, while an invalid legacy configuration now compiles correctly.
Reviewed By: javache
Differential Revision: D118438778
Pulled By: vzaidman
fbshipit-source-id: 650a70d8759b135cb06f9bd3f2b45b0ee766762b
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 https://github.com/react/react-native/issues/1889](https://github.com/react/metro/pull/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.
Pull Request resolved: https://github.com/react/react-native/pull/58249
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.
Reviewed By: christophpurrer
Differential Revision: D118499490
Pulled By: vzaidman
fbshipit-source-id: 3bd58c44c70415c57ed02266a5af2eea242471e4
Summary:
Development `-main` builds compute the Babel preset transformer cache key from preset JavaScript sources, but omit `package.json`. React Native regularly updates parser and Babel plugin dependencies without changing those source files, so a dependency-only update can preserve the cache key and reuse transforms produced by an older dependency set.
Include the preset package metadata bytes in the existing MD5 input. This adds one small file read only to the memoized `-main` slow path; published releases remain keyed directly by their immutable package version.
## Changelog:
[INTERNAL] [FIXED] - Invalidate React Native Babel preset development caches when dependency metadata changes.
Pull Request resolved: https://github.com/react/react-native/pull/58251
Test Plan:
- Added an isolated-module regression that supplies two package metadata contents with identical preset source contents; pristine main returns the same key, while the fix returns different keys.
- Full preset Jest passes: 5/5 suites, 111/111 tests, 16 snapshots.
- Fresh Flow check reports 0 errors.
- Targeted no-ignore ESLint, Prettier, and `git diff --check` pass.
No transform output, public API, published-release cache behavior, or UI changes.
Reviewed By: christophpurrer
Differential Revision: D118440621
Pulled By: vzaidman
fbshipit-source-id: 21d4df2d5bc0428d6cf2138b2f5230d777b7ddb0
Summary:
The preset's Babel-API accesses are optional, but invoking it without the Babel API still has two incomplete fallback paths: `preset()` can read properties from an undefined options object, and `getPreset(code, {dev: false})` receives no transform profile and silently falls back to legacy class transforms instead of the normal `hermes-stable` default.
Default options to an empty object, consistently rely on that non-null invariant throughout the configuration builder, and apply `hermes-stable` when neither explicit options nor `babel.caller` provides a profile. Explicit options and caller-provided profiles retain precedence.
## Changelog:
[GENERAL] [FIXED] - Apply normal preset defaults when invoked without a Babel API or options object.
Pull Request resolved: https://github.com/react/react-native/pull/58254
Test Plan:
- Added a regression proving `preset()` builds without options or a Babel API.
- Added a transform regression proving no-API invocation preserves classes under the default `hermes-stable` profile; exact baseline lowers the class to helpers.
- Full preset Jest passes: 4/4 suites, 112/112 tests, 16 snapshots.
- Fresh Flow check reports 0 errors.
- Targeted no-ignore ESLint, Prettier, and `git diff --check` pass.
No breaking change: explicit profiles/caller behavior are unchanged, while standalone invocation now matches the preset's documented default path.
Reviewed By: javache
Differential Revision: D118438065
Pulled By: vzaidman
fbshipit-source-id: e952eece72664dfa9d60d25d26955655e057f388
Summary:
The source-optimized preset enables React's display-name transform only when the exact bytes `React.createClass` are present. Valid comments or whitespace around the member access, such as `React /* comment */ . createClass(...)`, bypass the transform and omit the inferred component `displayName`, unlike the full preset path.
Use the stable `createClass` identifier token as the cheap source probe while retaining the separate `createReactClass` probe. Formatting no longer changes output; unrelated token matches only enable an otherwise no-op Babel visitor.
## Changelog:
[GENERAL] [FIXED] - Detect trivia-separated React.createClass calls in optimized preset configuration.
Pull Request resolved: https://github.com/react/react-native/pull/58256
Test Plan:
- Added an optimized-source regression with comment/whitespace-separated member access.
- Exact baseline omits `displayName`; the fixed transform emits `displayName: "Component"`.
- 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 public API or breaking behavior change; optimized and full preset paths now agree for valid formatting.
Reviewed By: GijsWeterings
Differential Revision: D118266439
Pulled By: javache
fbshipit-source-id: 802fe1c8cadda18931384cd5a7f6e88a63e87bad
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57973
`react-native/babel-preset` inlines `Platform.OS` and `Platform.select(...)` whenever it is handed a `platform` (since yesterday - https://github.com/react/react-native/pull/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
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57848
Adds a React Native-owned Babel plugin that inlines `Platform.OS` and
`Platform.select(...)`, from
`react-native/babel-preset` at the front of the preset's plugin list (importantly, before
the preset lowers ES modules to CommonJS).
Metro already inlines `Platform`, but its matcher (`metro-transform-plugins`'
`inline-plugin` via `createInlinePlatformChecks`) runs *after* ESM has been
lowered to CommonJS. By then a genuine `import {Platform} from 'react-native'`
has become `_reactNative.Platform.OS` and provenance is obscured and fragile to track. Metro compensates by matching on the local
identifier spelling - so `Platform.OS` inlines whether or not `Platform` is
actually React Native's, and a genuine deep or RN-relative import may be missed entirely.
`Platform` inlining is in any case much more of an RN concern than a Metro one - it has to be aware of RN APIs and module names, and even the module’s path.
This plugin recognises:
- `import {Platform} from 'react-native'` (including aliased imports)
- `import * as RN from 'react-native'`, uses of `RN.Platform`
- `import P from 'react-native/Libraries/Utilities/Platform'`
- the equivalent `require` forms, plus destructuring and immutable aliases
- RN's internal relative imports, e.g. `../../Utilities/Platform`
…and deliberately does *not* recognise anything it cannot prove - a bare
`Platform.OS` global, `React.Platform.OS`, or a same-named import from another
package.
Metro's late matcher is left fully enabled and remains responsible for
those historical forms, so this change is purely additive: it inlines genuine
imports Metro was missing, and changes nothing Metro already handled. Metro’s plugin will be deprecated and removed in future.
Notable details:
- Relative RN imports are resolved lexically, with no filesystem access and no
platform-extension resolution — the identity we need is the extension-less
module `<rn-root>/Libraries/Utilities/Platform`, and Metro picks
`Platform.ios.js` / `Platform.android.js` later. The RN package root is
identified by directory name, which covers `node_modules/react-native`,
`packages/react-native` and pnpm layouts alike, and rejects
`react-native-web` and friends (who would be expected to adjust the paths in their forks)
- Imports are left in place. Removing them would change dependency collection,
so it is handled separately.
- A no-platform build (`null`, or the empty string that RN's Jest preprocessor
passes) is a no-op — inlining `Platform.OS` to `""` would be wrong.
- The plugin source is added to the preset's `getCacheKey` so edits invalidate Metro's transform cache.
Changelog:
[General][Changed] - Inline `Platform.OS` and `Platform.select(...)` for
React Native `Platform` imports during the Babel preset, covering some cases that were previously left un-inlined.
Reviewed By: huntie
Differential Revision: D114647943
fbshipit-source-id: b44f38bd22970abba6e7d75c00fdbb27159c17a6
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57752
## Rationale
Flow lib defs that declare global types (available anywhere, without an `import`) must be referenced in `.flowconfig` and can't be maintained incrementally. That's not too bad for very stable APIs and it's necessary for environment/runtime globals, but for 3P libraries it makes the lib defs much more difficult to maintain for little benefit (we have to import the runtime APIs anyway). Secondarily, it's a problem for generating TypeScript types, as TS doesn't declare any 3P library globally.
Babel is one of few cases where a library declares Flow globals - every one has an importable equivalent.
## This diff
Replaces usages of Babel global types across xplat/js with their `babel/types` equivalents
Changelog: [Internal]
Reviewed By: javache
Differential Revision: D113574665
fbshipit-source-id: be668d968345a60e76a3515d19d8eaa002d53274
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57611
Directly follows D112733139 (Metro).
**Motivation**
- New Node builtins are *only* available under the prefix (e.g. `node:sqlite`), as this allows Node to introduce them without ecosystem-breaking changes, so this is the direction of travel and the only choice that'll allow consistency.
- Encouraging them and grouping them separately makes it easier to reason about a module's 3rd party dependencies.
Changelog: [Internal]
Reviewed By: robhogan
Differential Revision: D112803684
fbshipit-source-id: 40668d746a7151b3aa4800ff8af997902a18d198
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57475
NOTE: Resubmission of D110890810.
Replace `'react-native/Libraries/Core/InitializeCore'` with an explicit `'react-native/setup-env'` secondary export.
This was previously a special-case path excluded from our ESLint warnings. It is now formalised.
**Changes**
- Add new `src/setup-env.js` entry point and `package.json` mapping.
- Replace references in `packages/metro-config/` and `packages/community-cli-plugin/`.
- Update `warn-on-deep-imports` ESLint rule.
Changelog:
[General][Added] - Add `'react-native/setup-env'` entry point. This replaces the previous side-effectful `'react-native/Libraries/Core/InitializeCore'`.
[General][Deprecated] - Deprecate `'react-native/Libraries/Core/InitializeCore'`. Use `'react-native/setup-env'` instead.
Reviewed By: rubennorte
Differential Revision: D111022546
fbshipit-source-id: c9081997468b55b02c8a89544c7cb2026d625ad3
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57461
Replace `'react-native/Libraries/Core/InitializeCore'` with an explicit `'react-native/setup-env'` secondary export.
This was previously a special-case path excluded from our ESLint warnings. It is now formalised.
**Changes**
- Add new `src/setup-env.js` entry point and `package.json` mapping.
- Replace references in `packages/metro-config/` and `packages/community-cli-plugin/`.
- Update `warn-on-deep-imports` ESLint rule.
Changelog:
[General][Added] - Add `'react-native/setup-env'` entry point. This replaces the previous side-effectful `'react-native/Libraries/Core/InitializeCore'`.
[General][Deprecated] - Deprecate `'react-native/Libraries/Core/InitializeCore'`. Use `'react-native/setup-env'` instead.
Reviewed By: rubennorte
Differential Revision: D110890810
fbshipit-source-id: 3afe25efa45548d593a1b09c436e36038350b4c5
Summary:
Update `react-native/babel-preset` package metadata to use a `git+https` repository URL instead of the SSH-style URL. This avoids requiring SSH credentials for tooling that reads npm repository metadata.
## Changelog:
[INTERNAL]
Pull Request resolved: https://github.com/react/react-native/pull/57334
Test Plan: Parsed `packages/react-native-babel-preset/package.json` as JSON after the metadata update.
Reviewed By: christophpurrer
Differential Revision: D109713034
Pulled By: fabriziocucci
fbshipit-source-id: cf7119a032b96024babfa9238adc4d8e45347da7
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57273
**Motivation**
A README is the first thing an npm visitor sees on each package; internal-repo boilerplate like the "Testing" sections and the "We're using yarn…" note doesn't belong on a published package page.
**Changes**
- Standardize every README: a `# react-native/<name>` heading, a user-facing description, and a blue version badge plus a green monthly-downloads badge.
- Keep the "internal dependency" prelude only on `community-cli-plugin`, `virtualized-lists`, and `js-polyfills`.
- Drop the monorepo-template "Testing" sections and yarn note.
- Rework `metro-config` around the Configuring Metro guide; add missing READMEs for `metro-babel-transformer` and `popup-menu-android`.
Changelog: [Internal]
Reviewed By: emily8rown
Differential Revision: D109017270
fbshipit-source-id: 6208294c4ad2e6235a6605ae54f22d730f0476e7
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57258
Reflecting the move to https://github.com/react/react-native , update references in first-party `package.json`s
The `repository.url` field in particular is load-bearing for Trusted Publish.
Changelog: [Internal]
___
Reviewed By: fabriziocucci
Differential Revision: D108986410
fbshipit-source-id: 78513ffefc32ddf417dc1479a4834ebc44240080
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56887
Drop support for Node.js 20. The minimum supported version is now `^22.13.0 || ^24.3.0 || >= 26.0.0`.
Node.js 20 reached end-of-life in April 2026 and is no longer actively maintained. This aligns React Native with the upcoming Metro requirement.
Changelog:
[General][Breaking] - Require Node.js >= 22.13.0
Reviewed By: christophpurrer, cortinico
Differential Revision: D105685641
fbshipit-source-id: f490e5a13e4289daba98c4d56dd8fdd341aef0db
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56829
Disable `babel/plugin-transform-destructuring` when `customTransformOptions.unstable_preserveDestructuring` is truthy. This allows us to experiment with native destructuring support in Static Hermes.
Changelog: [Internal]
Reviewed By: vzaidman
Differential Revision: D93013925
fbshipit-source-id: bfc2b1cb8e04c28d2ae71b596bf759e3dc0e5701
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56825
Disable `babel/plugin-transform-block-scoping` when `customTransformOptions.unstable_preserveBlockScoping` is truthy. This allows us to experiment with native let/const block scoping support in Static Hermes.
Changelog: [Internal]
Reviewed By: vzaidman
Differential Revision: D93013927
fbshipit-source-id: 6e2c1274426943fcf1ce5a8c09d677e1d0afb35f
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56754
Hermes V1 (Static Hermes) is now always enabled. Remove the isHermesV1 variable and inline its effects:
- enableRegenerator is always based on dev mode (was isHermesV1 && dev)
- preserveClasses is always true (was isHermesV1)
Also update the comments to drop the 'V1' framing.
## Changelog:
[Internal] -
Reviewed By: cortinico
Differential Revision: D104649639
fbshipit-source-id: 70d4cbc0ad365df551b744e3cc16e880ce41c90c
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56254
Disable `babel/plugin-transform-async-to-generator` and `babel/plugin-transform-async-generator-functions` when `customTransformOptions.unstable_preserveAsync` is truthy. This allows us to experiment with native async/await support in Static Hermes.
Changelog: [Internal]
Reviewed By: vzaidman
Differential Revision: D93013928
fbshipit-source-id: 3a4bc5bad1a9ff5e7292961111524fef56cbcde7
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55880
Disable `babel/plugin-transform-private-methods` and `babel/plugin-transform-private-property-in-object` when `customTransformOptions.unstable_preserveClassPrivate` is truthy. This allows us to experiment with native private class field and method support in Static Hermes.
Changelog: [Internal]
Reviewed By: vzaidman, javache
Differential Revision: D93010263
fbshipit-source-id: 25c48c8561b7c9b4f8d9984e47c5ca8b14007360
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55918
To prevent crashes when a Babel plugin or preset is invoked without a Babel API object, ensure that any access to Babel-specific properties (such as babel.env) is guarded. Some build tools or environments may call Babel plugins without providing the full Babel API instance, leading to runtime errors if the code assumes its presence. By using optional chaining and providing safe fallbacks, you can maintain compatibility across different build systems (such as Metro and others) without introducing breaking changes.
Changelog:
[General][Fixed] Prevent errorrs by handling contexts where the Babel API object is not provided
Reviewed By: robhogan, rubennorte
Differential Revision: D94952379
fbshipit-source-id: 65e69c0510bc66930ee3b5f28e20df32d732f990
Summary:
Pull request resolved: https://github.com/facebook/react-native/pull/55805
Currently the RN Babel preset has this surprising bit of behaviour:
```js
module.exports = (options, babel) => {
if (options.withDevTools == null) {
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
if (!env || env === 'development') {
return getPreset(null, {...options, dev: true}, babel);
}
}
return getPreset(null, options, babel);
};
```
If the (undocumented, otherwise unused) `withDevTools` option is set (to anything), we will override any given value of `dev` to `true` if `BABEL_ENV` || `NODE_ENV || 'development' === 'development'`.
To put that another way, with `NODE_ENV=development` and `BABEL_ENV` unset, we would always produce a dev bundle even if `{ dev: false }`
Expo sets `withDevTools: false` to stop this happening, and always set `dev` (so this diff means **no observable change under Expo**):
https://github.com/expo/expo/blob/4a46dbff7a5a77d9fe06d30a70d7fab38cfc7f9a/packages/babel-preset-expo/build/index.js#L235-L236
This odd-looking override was introduced in 2017 in https://github.com/facebook/react-native/commit/bc22a4da7ea74d17cd701717268c8e50f001d614 / D5237158 as a way to gate `babel/plugin-transform-react-jsx-source`, *before the preset accepted any other options* - it was never intended to override `dev`. Now, we gate that same plugin under `options.dev`.
## Inferring `dev` when unspecified
The one potentially load-bearing piece of this is that, when a consumer specifies neither `withDevTools` nor `dev` (or maybe no options at all), this code serves to infer it from `process.env.BABEL_ENV || process.env.NODE_ENV`, which is reasonable and actually closer to the way typical plugins/presets work, but a better mechanism compatible with Babel's cache is to use the `env()` API (which defaults to `process.env.BABEL_ENV || process.env.NODE_ENV`, so preserves behaviour).
https://babeljs.io/docs/config-files#apienv
## This change
- Removes the obsolete use of `withDevToolss`, and never overrides the explicitly-passed `dev`
- Where `dev` is not specified, falls back to the Babel environment.
Changelog:
[General][Fixed] Babel-preset: Don't override explicitly-passed `dev` config if obsolete `withDevTools` is missing
Reviewed By: huntie
Differential Revision: D94660480
fbshipit-source-id: 5dfae8fb704e6881b03120cd14510795382a98ba
Summary:
This implements the proposal to split the Jest preset (and dependencies) out into a separate package: https://github.com/react-native-community/discussions-and-proposals/pull/926
- `react-native` has an optional peer dependency on `react-native/jest-preset`
- `react-native/jest-preset.js` throws when `react-native/jest-preset` isn't installed and instructs the user to add it to migrate
- `react-native/jest-preset` may be used directly as a Jest preset
## Changelog:
[General][Breaking] - Move Jest preset to new `react-native/jest-preset` package
Pull Request resolved: https://github.com/facebook/react-native/pull/55169
Test Plan:
The jest preset is used, with some modifications, in `facebook/react-native` itself and CI should confirm that the changes work. Running `jest` on the repo similarly validates that the preset still works.
Otherwise, nothing has changed and the easiest way to test this is to use the preset in an existing project and try both `preset` set to the current value and `preset` set to `"react-native/jest-preset"`
Reviewed By: cipolleschi
Differential Revision: D91700684
Pulled By: huntie
fbshipit-source-id: ee4a7d3ceb4934a3d0f7558d93dc601ea4b8dfa8