-
-
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
[DatePicker] Use only path imports from @material-ui/core #24146
Comments
Hmm, I am not really sure about why? In theory, webpack should understand that we are importing the same file.
By the way, is there any eslint plugin that will automatically change the import. If no – I can write one |
@dmtrKovalenko |
ohh god, really... thanks @TrySound then its definitely a problem |
It can be verified with this sandbox https://codesandbox.io/s/wonderful-yonath-5cted?file=/src/App.js I have deployed for production in https://csb-5cted.netlify.com/. |
unstable_TrapFocus export is a good way to go for internal usage. |
I mean overall. Does import from the core for the current build is somehow worse than path import? |
We have this eslint plugin for internal usage of the mono-repository: https://github.com/mui-org/material-ui/blob/master/packages/eslint-plugin-material-ui, It could be great to publish it on npm for external users. If this is something you want to work on 👍.
Regarding, the why. Let's take my repository and expand the resolution, using equivalences: import { Dialog } from '@material-ui/core';
import { DateRangePicker } from '@material-ui/pickers'; <=> import Dialog from '@material-ui/core/esm/Dialog.js';
import TrapFocus from '@material-ui/core/Modal/TrapFocus'; <=> import Modal from '@material-ui/core/esm/Modal.js';
https://unpkg.com/browse/@material-ui/core@4.9.10/Modal/TrapFocus.js <=> https://unpkg.com/browse/@material-ui/core@4.9.10/esm/Modal/TrapFocus.js
https://unpkg.com/browse/@material-ui/core@4.9.10/Modal/TrapFocus.js |
I figured out why. But another question of why do we need an |
Ok great
It explained in https://material-ui.com/guides/minimizing-bundle-size/. Adding @eps1lon to the loop. |
So I suppose we need to just use core imports on core documentation overall. |
Allowing certain path imports by convention is definitely a brittle approach. In the future we likely leverage export maps so that it's obvious what's allowed and what isn't.
Because it would require rewriting file extensions instead. We use relative imports without extensions throughout the codebase and it's not clear to me that all bundlers (during v4 development) were capable of figuring out which files is meant when importing The goal is definitely to publish a correct ES modules build at some point but we need to know if this works across bundlers and need to implement this as well. The Either way
seems like good tradeoff. We definitely don't want to add more exceptions to what kind of path imports are allowed.
Not really following what you mean. We shouldn't use path imports deeper than |
@eps1lon thanks for description. I am not 100% sure why we cannot use |
Tree-shaking is by default a production-only feature in webpack 4 and earlier (not sure about 5). This means that webpack will parse the full It doesn't affect user code at all. It's a dev-only optimization. I haven't followed the discussion around this so this might've changed in new versions of webpack. |
Thanks, got it @eps1lon For now, I`ll just copy and enhance the rule from the https://github.com/mui-org/material-ui/tree/master/packages/eslint-plugin-material-ui |
We should probably bite the bullet and publish a babel plugin for that. Having different approaches floating around in "userspace" is pretty dangerous. The only problem is how we make it compatible with any (minor v4) version of Material-UI. |
I ended up needing it recently so I just copied and pasted it. But I was wondering what's left to do and why it can't just be published? Seems to be working fine? Sorry if this isn't the right repo to discuss. |
@mbrookes Could you extend the number of people that have the publish rights on https://www.npmjs.com/package/eslint-plugin-material-ui? I think that it could be interesting to publish a new version, at least for internal usage. |
@mbrookes Thanks, yeah wow. |
I can't now remember why it was published in the first place, considering it's only used internally... 🤔 |
Material-UI forbid imports over two levels as it can lead to duplication in people bundles. Meaning, if somebody does:
It will bundle 1. and 2.:
Now, given we do:
https://github.com/mui-org/material-ui-pickers/blob/7bed283699ef768936a3ec7c5dc89571492dddd4/lib/src/wrappers/DesktopPopperWrapper.tsx#L6
in the codebase, we very likely cause this double bundling quite often. For instance:
The text was updated successfully, but these errors were encountered: