question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unused modules in bundle

See original GitHub issue

I’ve started analyzing material-ui part (quite big as it turned out) of my application bundle. My app is very simple for now, I use not many different widgets, so I was quite surprised seeing modules like Popover inside the bundle. I’ve traced dependency graph and I found quite a long path from Select (which I consciously use), through SelectInput and Menu modules, to that Popover thing. Why would I need it, I asked myself, I use only native Select! Quick look at source code of SelectInput gave me the answer: module Menu, which depends on Popover, is eagerly loaded even if it’s not actually used. render method of SelectInput returns early in native branch of code and this is obviously not traceable by any three-shaker.

I don’t have extensive experience with material-ui, so I don’t know if native select is the only such case or that pattern (I mean conditional usage of component based on runtime properties) is common in the project. Are you interested in optimizaton of this? I suppose for big and large projects, using a lot of different UI components, it’s not an issue at all, as that Popover component will be used in some other place eventually. For me, personally, savings are quite significant, though. Removing Menu and all its dependencies shrinks my bundle by 8% (11.5 kB gzipped).

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

Expected Behavior

I’m able to use native select component without loading bunch of components used by not-native implementation.

Current Behavior

No matter if I use native or custom select, I have all code required by the latter one in my bundle.

Steps to Reproduce (for bugs)

https://codesandbox.io/s/p79koy741j

select

Quite a lot of dependencies for a single native select, don’t you think?

Context

It affects performance somehow (I cannot provide you real numbers, but think of downloading 11.5 kB and parsing around 50 kB of never used JS). And performance matters, right?

Your Environment

Tech Version
Material-UI 1.0.0-beta.33
React 16.2.0
browser any
etc -

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Mar 28, 2018

Will <Select native /> still be available?

@dantman Yes, we can. The <Select native /> implementation overhead is minimal. But what about?

const Select = isMobile ? MuiNativeSelect : MuiSelect;

<Select />

Maybe it’s not needed after all.

1reaction
oliviertassinaricommented, Mar 28, 2018

What about moving forward on this issue by exposing a Select and a NativeSelect component? We can share the same stylesheet and Select.render() implementation between the two versions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unused exports added in webpack bundles - Stack Overflow
Unused exports added in webpack bundles · We use ES2015 module syntax (i.e. import and export). · @babel/preset-env is configured with modules: ...
Read more >
Unused modules in bundle #10335 - mui/material-ui - GitHub
I'm able to use native select component without loading bunch of components used by not-native implementation. Current Behavior. No matter if I ...
Read more >
Delete Unused Code with Webpack and unused-files ...
By the end of the lesson, you'll have a useful cli command you can run to check for unused modules in your Webpack...
Read more >
Tree shaking and code splitting in webpack - LogRocket Blog
What is tree shaking? Tree shaking, also known as dead code elimination, is the practice of removing unused code in your production build....
Read more >
Tree Shaking - webpack
Its main purpose is to bundle JavaScript files for usage in a browser, ... ES2015 modules (alias harmony modules) as well as unused...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found