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

[TextField] Optimize imports so that unneeded components are not bundled. #9262

Closed
1 task done
Graham42 opened this issue Nov 21, 2017 · 10 comments
Closed
1 task done
Labels
component: text field This is the name of the generic UI component, not the React module! performance

Comments

@Graham42
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

When using just a couple TextFields and a Button (ie. a login page) and using the babel-plugin-direct-import module, I would expect that only the TextField and Button components should be bundled in the ouput.

Current Behavior

Many other components including List, Menu, and Popover get included in the bundle.

Steps to Reproduce (for bugs)

I have created a sample project that just uses a TextField.

  1. git clone https://github.com/Graham42/bug-babel-direct-import-material-ui-next
  2. npm install
  3. You can see the module bundle stats by running
npm run build
npm run stats

Context

I'm trying to minimize the bundle size of what needs to be delivered for my login page.

Your Environment

Tech Version
Material-UI 1.0.0-beta.21
React 16.1.1
babel-plugin-direct-import 0.4.0
@mbrookes
Copy link
Member

@Graham42 Please refer to the linked issue for an explanation.

@Graham42
Copy link
Author

Can this component not be refactored to not pull in Select? Seems like Select should depend on TextField not the other way around.

@Graham42
Copy link
Author

For additional context. This has an impact of 84 KB of unneeded extra code in my bundle because I'm not using the select option on TextField

@mbrookes
Copy link
Member

mbrookes commented Nov 21, 2017

Can this component not be refactored to not pull in Select?

Go for it! 😉

(I'll admit it does seem a bit topsy-turvy at first glance, but given its provinance, I have to assume it was done this way for good reason. )

Edit: spelling.

@Graham42
Copy link
Author

I can see from the original issue and pull request that the discussion centered around the component API and usability with makes sense. However app bundle size didn't come up.

Please reopen this issue as it has not been resolved.

@mbrookes mbrookes added component: text field This is the name of the generic UI component, not the React module! performance Priority: low labels Nov 22, 2017
@mbrookes
Copy link
Member

mbrookes commented Nov 22, 2017

Done. I understand your concern, so lets put it out there for feedback.

Edit: I used the "performance" label as a proxy for bundle-size, as we don't seem to have anything more appropriate.

@mbrookes mbrookes added the waiting for 👍 Waiting for upvotes label Nov 22, 2017
@mbrookes mbrookes reopened this Nov 22, 2017
@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 7, 2017

I don't think there is anything more we can do about it. You have different solutions available:

  • import directly the component you need.
  • rely on the es modules and tree shaking
  • submit a pull-request on babel-plugin-direct-import to make the logic smarter.

@JulesAU
Copy link

JulesAU commented Feb 8, 2018

@oliviertassinari Just trying to make sure I understand your response: "import directly the component you need."

Does that mean I can work around this particular issue? I'm also seeing the redundant Select component in my production bundle due to my use of TextField - I'm importing it as per the material-ui docs:

import TextField from 'material-ui/TextField';

Is there anything I can do differently to avoid this, or do we just need wait until tree-shaking and/or babel-plugin-direct-import work better?

@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 8, 2018

import directly the component you need.

@JulesAU What I mean is that the TextField is a helper to simplify the usage of the underlying components. If you want to save some bundle size. It's 100% fine to write your own TextField component without the Select import. https://material-ui.com/demos/text-fields/#components

@JulesAU
Copy link

JulesAU commented Feb 8, 2018

Ahh of course... Thanks for the tip!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! performance
Projects
None yet
Development

No branches or pull requests

4 participants