Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement plugin-transform-react-pure-annotations and add to preset-react #11428

Merged
merged 2 commits into from May 24, 2020

Conversation

devongovett
Copy link
Contributor

@devongovett devongovett commented Apr 16, 2020

Q                       A
Fixed Issues? Closes #11399
Patch: Bug Fix? No
Major: Breaking Change? No
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This implements @babel/plugin-transform-react-pure as described in #11399, and adds it by default to @babel/preset-react. This plugin adds /*#__PURE__*/ annotations before many top-level React function calls, which allows them to be tree shaken/dead code eliminated by terser and other minifiers.

For example, libraries making use of React.forwardRef or React.memo could be tree shaken if unused. For apps using large libraries of components that use these APIs, this could make a big difference to overall bundle size.

This is built into @babel/preset-react by default for maximum impact across the ecosystem. However, it can be disabled by setting the {"pure": false} option to the preset, which also already disables pure annotations on compiled JSX.

@existentialism existentialism added PR: New Feature 🚀 A type of pull request used for our changelog categories area: react labels Apr 16, 2020
Copy link
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.

Awesome!

I would like the plugin to be named @babel/plugin-transform-react-pure-annotations, since I find it more descriptive of what it does.

Apart from that, the code looks good 👍

@nicolo-ribaudo
Copy link
Member

The CI failure doesn't seem related to this PR, but it doesn't fail on master and it fails on every node version 🤔

@nicolo-ribaudo
Copy link
Member

Ok, I restarted travis on master and it failed.

@nicolo-ribaudo nicolo-ribaudo added this to the v7.10.0 milestone Apr 16, 2020
@devongovett
Copy link
Contributor Author

Updated the plugin name. I'm not sure what's up with the tests. They do pass locally...

Copy link
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.

Tests fixed by #11432

Copy link
Member

@existentialism existentialism left a comment

Choose a reason for hiding this comment

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

👍

@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 Apr 16, 2020
@nicolo-ribaudo nicolo-ribaudo changed the title Implement transform-react-pure and add to preset-react Implement plugin-transform-react-pure-annotations and add to preset-react May 17, 2020
@nicolo-ribaudo nicolo-ribaudo merged commit 6ba1f0d into babel:master May 24, 2020
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Aug 24, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: react outdated A closed issue/PR that is archived due to age. Recommended to make a new issue 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.

Automatically annotate React.forwardRef as PURE
3 participants