Gate jsxDEV source/self with developmentSourceSelf option#17845
Gate jsxDEV source/self with developmentSourceSelf option#17845nicolo-ribaudo merged 4 commits intobabel:mainfrom
developmentSourceSelf option#17845Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61107 |
|
commit: |
|
HI @JLHwung |
JLHwung
left a comment
There was a problem hiding this comment.
Thank you, this PR looks good to me.
I marked this PR as a breaking change because we will not release new minor for Babel 7 and the new output may not work with old React versions.
Could you also prepare a docs update to the babel-website? Specifically, we will need a migration note mentioning this change in https://github.com/babel/website/blob/main/docs/v8-migration.md
|
The CI error is not related and has been fixed on main. I will rebase this branch to make the CI green. |
17ec005 to
9fa3a62
Compare
Done i have prepare a docs update to the babel-website... |
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
Thanks, this looks good to me and I agree with the new default.
I don't know if we'll have another Babel 7 minor release, but if we do, do you think we should backport this PR (with the default value flipped to true)?
|
yeah I think backporting makes sense. with the default set to |
| pragma: PRAGMA_DEFAULT = DEFAULT.pragma, | ||
| pragmaFrag: PRAGMA_FRAG_DEFAULT = DEFAULT.pragmaFrag, | ||
|
|
||
| developmentSourceSelf: DEVELOPMENT_SOURCE_SELF = false, |
There was a problem hiding this comment.
This option should be passed from createPlugin, rather than the returned plugin callback. The main plugin should not be aware of the developmentSourceSelf option.
…tions Move developmentSourceSelf from the Options interface (user-facing plugin options) to the createPlugin factory parameter. This ensures the main plugin is not aware of the developmentSourceSelf option. The preset-react now imports createPlugin directly and passes developmentSourceSelf when creating the development plugin instance.
9fa3a62 to
6b7b62d
Compare
|
The CI error is related, could you run |
|
@JLHwung Done |
|
Merging, thanks :) It'd be great if you could also prepare a backport PR targeting the |
developmentSourceSelf option
Backport of babel#17845 to the 7.x branch, as requested by nicolo-ribaudo. Adds a `developmentSourceSelf` option to `@babel/preset-react` (and `sourceSelf` to the underlying JSX development plugin) that controls whether `__source` and `__self` attributes are injected in jsxDEV calls. React 19.2+ generates these from the callsite, making Babel injection unnecessary and sometimes harmful (duplicated props warnings). Default on 7.x: `true` (preserves backward compatibility). Default on 8.x: `false` (React 19.2+ is the common target). Users on React 19.2+ can opt out with: { "runtime": "automatic", "developmentSourceSelf": false }
#17866 |
React 19.2 removed the
sourceandselfparameters fromjsxDEV. Babel still unconditionally generates them in development mode which causes unnecessary overhead.This PR adds a
developmentSourceSelfoption to@babel/plugin-transform-react-jsxand@babel/preset-react. When set totruethe plugin generates__sourceand__selfas before. The default isfalsein Babel 8 so the output aligns with the current React runtime.Users who still need these arguments (e.g. older React versions or custom runtimes) can opt back in:
{ "presets": [ ["@babel/preset-react", { "development": true, "developmentSourceSelf": true }] ] }