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

Mark . (dot) notation components as PURE. #3225

Open
Hugos68 opened this issue Feb 17, 2025 · 2 comments
Open

Mark . (dot) notation components as PURE. #3225

Hugos68 opened this issue Feb 17, 2025 · 2 comments
Labels
feature request Request a feature or introduce and update to the project.
Milestone

Comments

@Hugos68
Copy link
Contributor

Hugos68 commented Feb 17, 2025

Describe the feature in detail (code, mocks, or screenshots encouraged)

Currently we define components using the following syntax:

const Root = ...;
const SubComponent = ...;

export const Component = Object.assign(Root, { SubComponent });

This works great but means that if Component is imported, all subcomponents, used or not used, are bundled.
For bundlers to do their job correctly we can utilize the /*#__PURE__*/ comment to mark an object as "pure" meaning that the properties can be treeshaken individuaally without affecting one or another. We should add these comments to our exported . components.

It would look something like this:

const Root = ...;
const SubComponent = ...;

export const Component = /*#__PURE__*/ Object.assign(Root, { SubComponent });

What type of pull request would this be?

Enhancement

Provide relevant links or additional information.

https://github.com/javascript-compiler-hints/compiler-notations-spec/blob/main/pure-notation-spec.md
https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sideeffects

@Hugos68 Hugos68 added the feature request Request a feature or introduce and update to the project. label Feb 17, 2025
@endigo9740 endigo9740 added this to the v3.0 (Next) milestone Feb 17, 2025
@phamduylong
Copy link
Contributor

Components to update:

  • Accordion
  • Navigation
  • Segment (is there even a use case that includes Segment and doesn't involve Segment.Item)??
  • Tabs

@endigo9740
Copy link
Contributor

@phamduylong there's not a use case that involves any of these components being used without their parent. The only kind of edge case here is Navigation has two possible parents: Rail or Bar. So you would never use Rail and Bar as the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request a feature or introduce and update to the project.
Projects
None yet
Development

No branches or pull requests

3 participants