-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[zero] Move extendTheme to its own subpath #41204
Conversation
fixing the size of runtime bundle
Netlify deploy previewhttps://deploy-preview-41204--material-ui.netlify.app/ Bundle size report |
@@ -81,3 +82,5 @@ export function withZeroPlugin(nextConfig: NextConfig, zeroConfig: ZeroPluginCon | |||
webpack, | |||
}; | |||
} | |||
|
|||
export { extendTheme }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to reexport it from the plugin? I am afraid that it might be confusing for users especially with auto import/autocomplete in IDE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll reduce the mental overhead for users trying to import this.
Ideally, they should only think of @mui/zero-runtime
imports to be imported only in their source code, not in the config files outside the source.
They should only use bundler specific package in their config and zero runtime in source code.
That's why in the main export of zero runtime, I've only added what you could similarly import from emotion.
Other exports are in subpaths mainly to share same logic across different bundler plugins that we'll support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. What's your thought @mnajdova ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should only use bundler specific package in their config and zero runtime in source code.
In general this makes sense to me 👍
fixing the size of runtime bundle
Context -
zero-runtime package has 2 different types of exports -
import {styled} from '@mui/zero-runtime';
import {generateCss} from '@mui/zero-runtime/utils'
package level exports should be what we want to end-up in the final bundle and subpaths is for sharing common logic across different bundle plugin implementation (ie, implement the common functionality in one place and import and use it it next/vite plugin).
When @siriwatknp implemented the
extendTheme
functionality, he added it directly to the package level export, ie,import {extendTheme} from '@mui/zero-runtime';
. I think this was an oversight as without proper tree-shaking,extendTheme
will also end-up being part of the bundle (which also includes@mui/system
).So I was mainly fixing that. So moved it to its own subpath (
@mui/zero-runtime/extendTheme
). While doing this, I also made the change to re-export these items from the bundle specific packages as well.My thinking is that if users are configuring their bundler, they should only import stuff from the bundler package and think of
@mui/zero-runtime
as the runtime package. Rest of the context is here.