Repository navigation
Commit 305ab93
authored
Babel preset: Remove jsx-source and jsx-self plugins
Fixes absolute source paths appearing in (dev-only) transform output, which could cause fresh and shared-cache builds to differ cosmetically.
## Summary
In dev, `@react-native/babel-preset` adds `@babel/plugin-transform-react-jsx-source`, which embeds each file's absolute path in a `_jsxFileName` variable. Nothing has read that value for ordinary JSX since the preset moved to the automatic runtime in react/metro#849 (RN 0.70), because Babel extracts `__source` and discards it unless `development` is set. That leaves an unused declaration in every module with JSX.
`createElement` paths (key-after-spread, per-file `@jsxRuntime classic`) do still pass `__source`, but React has ignored it since react/react#28265 (React 19). Source locations come from `_debugStack` and source maps instead. This removes both plugins, as `babel-preset-expo` did in expo/expo#45351.
The motivation is that transforms become independent of the project root. Once #58584 lets checkouts share a transform cache, this also stops one checkout being served another's paths.
The only observable difference I know of is that a custom classic factory (`/** @jsx h */`) no longer receives `__source`. At worst, that breaks a fragile assumption in dev only in a very niche case.
## Changelog
[General][Removed] - Babel preset: Remove `@babel/plugin-transform-react-jsx-source` and `@babel/plugin-transform-react-jsx-self`, as React no longer reads their output
## Test plan
AI-driven. On main, the RNTester Android dev bundle goes from 270 `_jsxFileName` declarations to zero, and those were the only occurrences of the checkout path, for a 0.75% smaller bundle.
The rest ran with this change applied to the installed preset in a 0.88.0 template app (React 19.3.0) plus a probe screen, on an Android emulator:
- Bundles: dev bundles built at two project roots are byte-identical except for the `sourceMappingURL` filename.
- Shared cache: with `asyncRequireModulePath` set to `metro:runtime/modules/asyncRequire`, as in #58584, and a shared `FileStore`, the second root gets a full cache hit and a byte-identical bundle. Without this change, that bundle carries 71 of the first root's paths.
- Runtime: element shape, inspector hierarchy, component stacks, symbolicated frames, LogBox content and open-in-editor target all match the unpatched preset, over 3 rounds per variant and then 6 interleaved.
- DevTools: driving the backend over CDP, source locations differ only for LogBox internals, and that set varies per run.
- LogBox's hidden frame count varied between runs (10-13) in both variants, with matching app frames. I can't separate the variants at this sample size, but this change doesn't touch that code.
Not tested: iOS, physical devices, or the DevTools frontend UI.
Differential Revision: D129319560
Pull Request resolved: #597751 parent b255245 commit 305ab93
10 files changed
Lines changed: 0 additions & 28 deletions
File tree
- packages/react-native-babel-preset
- src
- __tests__/__fixtures__/output
- configs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | 233 | | |
239 | 234 | | |
240 | 235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
844 | 844 | | |
845 | 845 | | |
846 | 846 | | |
847 | | - | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | | - | |
857 | | - | |
858 | | - | |
859 | | - | |
860 | | - | |
861 | 847 | | |
862 | 848 | | |
863 | 849 | | |
| |||
0 commit comments