Skip to content

[7.x backport] Add developmentSourceSelf to JSX transform#17866

Open
rootvector2 wants to merge 1 commit intobabel:7.xfrom
rootvector2:backport-developmentSourceSelf-7x
Open

[7.x backport] Add developmentSourceSelf to JSX transform#17866
rootvector2 wants to merge 1 commit intobabel:7.xfrom
rootvector2:backport-developmentSourceSelf-7x

Conversation

@rootvector2
Copy link
Copy Markdown
Contributor

Summary

Backport of #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).

Defaults

Branch Default Rationale
7.x (Babel 7) true Preserves backward compatibility
7.x (Babel 8 path) false React 19.2+ is the common target

Usage

Users on React 19.2+ can opt out:

{
  "presets": [["@babel/preset-react", {
    "runtime": "automatic",
    "developmentSourceSelf": false
  }]]
}

Changes

  • create-plugin.ts: Added sourceSelf option to development plugin; gates __source/__self injection behind it
  • normalize-options.ts: Added developmentSourceSelf validation/normalization with appropriate defaults
  • preset index.ts: Passes developmentSourceSelf through as sourceSelf to plugin
  • Test fixtures updated to explicitly set sourceSelf: true / developmentSourceSelf: true where needed
  • New test fixtures for sourceSelf: false / developmentSourceSelf: false behavior

All tests pass in both Babel 7 and Babel 8 modes.

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 }
@babel-bot
Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61161

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 12, 2026

Open in StackBlitz

commit: 0cdd5f3

@nicolo-ribaudo nicolo-ribaudo changed the title feat: gate jsxDEV __source/__self with developmentSourceSelf option (7.x backport) [7.x backport] Gate jsxDEV source/self with developmentSourceSelf option Mar 12, 2026
@nicolo-ribaudo nicolo-ribaudo changed the title [7.x backport] Gate jsxDEV source/self with developmentSourceSelf option [7.x backport] Add developmentSourceSelf to JSX transform Mar 12, 2026
@nicolo-ribaudo nicolo-ribaudo added PR: New Feature 🚀 A type of pull request used for our changelog categories ⚠️ Do not merge labels Mar 12, 2026
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Will merge this if/when we have a minor release for Babel 7.

@nicolo-ribaudo nicolo-ribaudo added the PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.x: backport ⚠️ Do not merge PR: New Feature 🚀 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants