Skip to content

Automatically annotate React.forwardRef as PURE #11399

@devongovett

Description

@devongovett

Feature Request

  • I would like to work on this feature!

Is your feature request related to a problem? Please describe.

When building an app with React, React.forwardRef calls prevent tree shaking unused components. This can be fixed by adding a /*#PURE*/ annotation so terser knows it's safe to remove. I think @babel/preset-react could do this automatically.

Describe the solution you'd like

Either @babel/plugin-transform-react-jsx or a separate plugin could add /*#PURE*/ comments when forwardRef calls are seen.

Describe alternatives you've considered

A separate plugin outside the babel monorepo. But then it would be up to individual apps to adopt that plugin rather than getting this for free just by upgrading babel.

Teachability, Documentation, Adoption, Migration Strategy

Would happen automagically. 😉

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: reactoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions