Repository navigation
Conversation
robhogan
force-pushed
the
pr1957
branch
2 times, most recently
from
September 21, 2026 14:34
d9dcf8f to
cb7a1fe
Compare
robhogan
force-pushed
the
pr1957
branch
2 times, most recently
from
September 21, 2026 15:10
17e21c7 to
fea257f
Compare
8388f71 added the `metro:` scheme resolver, which maps `metro:babel-runtime/<path>` to metro-runtime's own `@babel/runtime`. This is the Metro half of pointing `@babel/plugin-transform-runtime` at it - the preset half is react/react-native#57974, and until a preset reads it this is a no-op. When `transformer.enableBabelRuntime` is `true` (the default), Metro now passes presets `babelRuntimeModuleName: 'metro:babel-runtime'` and that copy's installed version as Babel caller data, matching what `@react-native/babel-preset` reads. Caller data reaches a preset however it's configured, including from a project `babel.config.js`. The version is read from the installed package, so its `package.json` joins the transform cache key. A string `enableBabelRuntime` (a version of the project's own `@babel/runtime`) keeps its meaning and passes neither. It's now documented as deprecated. With presets importing from it, Metro's `@babel/runtime` needs to be in the file map, and Metro adds it as a root at startup when no configured root contains it. If that fails (eg the watcher can't watch it), Metro now warns and starts anyway, rather than failing for projects that never import from it. Changelog: ``` - **[Feature]**: When `transformer.enableBabelRuntime` is `true`, pass Metro's own `@babel/runtime` (`metro:babel-runtime`) and its installed version to Babel presets via caller data - **[Deprecated]**: String values of `transformer.enableBabelRuntime` (use `true`) ``` Test plan: New integration test builds and runs a bundle through the full Metro + Babel pipeline, with a preset that reads the caller data as `@react-native/babel-preset` does. Its fixture uses `import * as`, whose helper `@babel/runtime` only exports from 7.14.0, so the helper is imported rather than inlined only if the version reaches the preset. Covered with `enableBabelRuntime` both `true` and `false`. Metro's `@babel/runtime` sits outside the test's watch folders, so this also exercises the dynamic root from #2065 end to end.
This branch has not been deployed
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.
8388f71 added the
metro:scheme resolver, which mapsmetro:babel-runtime/<path>to metro-runtime's own@babel/runtime. This is the Metro half of pointing@babel/plugin-transform-runtimeat it - the preset half is react/react-native#57974, and until a preset reads it this is a no-op.When
transformer.enableBabelRuntimeistrue(the default), Metro now passes presetsbabelRuntimeModuleName: 'metro:babel-runtime'and that copy's installed version as Babel caller data, matching what@react-native/babel-presetreads. Caller data reaches a preset however it's configured, including from a projectbabel.config.js. The version is read from the installed package, so itspackage.jsonjoins the transform cache key.A string
enableBabelRuntime(a version of the project's own@babel/runtime) keeps its meaning and passes neither. It's now documented as deprecated.With presets importing from it, Metro's
@babel/runtimeneeds to be in the file map, and Metro adds it as a root at startup when no configured root contains it. If that fails (eg the watcher can't watch it), Metro now warns and starts anyway, rather than failing for projects that never import from it.Changelog:
Test plan:
New integration test builds and runs a bundle through the full Metro + Babel pipeline, with a preset that reads the caller data as
@react-native/babel-presetdoes. Its fixture usesimport * as, whose helper@babel/runtimeonly exports from 7.14.0, so the helper is imported rather than inlined only if the version reaches the preset. Covered withenableBabelRuntimebothtrueandfalse. Metro's@babel/runtimesits outside the test's watch folders, so this also exercises the dynamic root from #2065 end to end.