-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
Unused modules in bundle #10335
Comments
@erykpiast Thanks for raising this issue! I agree. We need to do something. The best option I can think of is having two |
Maybe it's not perfect, but one alternative might be to add some sort of global constants. Like Then if you are one of the subset of people that doesn't use non-native inputs you can declare those in your bundler's config. Then that would become Basically, the same way Alternatively we could provide an official WebPack plugin like lodash-webpack-plugin (or perhaps a babel plugin). Which will change |
@dantman It may work, but I think it’s more than native select. It’s about managing dependencies carefully. |
What about moving forward on this issue by exposing a |
@oliviertassinari |
@dantman Yes, we can. The const Select = isMobile ? MuiNativeSelect : MuiSelect;
<Select /> Maybe it's not needed after all. |
I can just say that the solution with separate native select component could solve my issue. In my opinion it’s good enough for now, especially if it doesn’t introduce breaking change to existing API :) |
I also think a separate NativeSelect component sharing most of it's code with Select would be preferrable |
@olee Do you think we should keep supporting |
Yes, because in a way, the non-native select is just an extension to the native select in a way and there's nearly no component overhead in importing |
sorry for the ot question here, but where does the "isMobile" come from? I cannot find it anywhere in the docs, so i guess it's a 3th party package? Could be useful to add this to the docs as well. |
@sakulstra From some of your internal logic. You can use user-agent, screen-width, touch support or any other heuristics as you see fit. |
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 likePopover
inside the bundle. I've traced dependency graph and I found quite a long path fromSelect
(which I consciously use), throughSelectInput
andMenu
modules, to thatPopover
thing. Why would I need it, I asked myself, I use only nativeSelect
! Quick look at source code ofSelectInput
gave me the answer: moduleMenu
, which depends onPopover
, is eagerly loaded even if it's not actually used.render
method ofSelectInput
returns early innative
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 thatPopover
component will be used in some other place eventually. For me, personally, savings are quite significant, though. RemovingMenu
and all its dependencies shrinks my bundle by 8% (11.5 kB gzipped).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
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
The text was updated successfully, but these errors were encountered: