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

React Constant Element transformation support #7318

Closed
SukkaW opened this issue Apr 23, 2023 · 3 comments
Closed

React Constant Element transformation support #7318

SukkaW opened this issue Apr 23, 2023 · 3 comments

Comments

@SukkaW
Copy link
Contributor

SukkaW commented Apr 23, 2023

Describe the feature

This plugin can speed up reconciliation and reduce garbage collection pressure by hoisting React elements to the highest possible scope, preventing multiple unnecessary re-instantiations.

Babel plugin or link to the feature description

https://babeljs.io/docs/babel-plugin-transform-react-constant-elements

Additional context

// In
const Hr = () => {
  return <hr className="hr" />;
};

const WithChildren = (props) => {
  return <div className={props.className}>
    <hr />
  </div>;
}

// Out
var _hr, _hr2;

const Hr = () => {
  return _hr || (_hr = <hr className="hr" />);
};

const WithChildren = (props) => {
  return <div className={props.className}>
    {_hr2 || (_hr2 = <hr />)}
  </div>;
}
@kwonoj
Copy link
Member

kwonoj commented Apr 23, 2023

It looks like babel supports via plugin, any reason it can't be swc plugin?

@kwonoj
Copy link
Member

kwonoj commented May 18, 2023

Closing as not hearing any more information for the core between plugin. If you still believe this should be in a core transform, please feel free to file a new RFC #4162 with usecases that it cannot be done by plugin.

@kwonoj kwonoj closed this as completed May 18, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Jun 18, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Jun 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants