-
-
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
[material-ui-icons] load-order problem with SSR and ES6 use of material-ui; needs ES variant? #10649
Comments
@estaub This issue has already been discussed in #10212. The status quo is, only use the A possible good solution would be to implement #10212 (comment), but the risk is high compared to the low output. I'm not sure what's your use case for using the |
I'm using /es to shrink material-ui's footprint using webpack. If there's some other way to do that, that doesn't involve dragging babel into my toolchain, I'm all ears! |
Hey! Any news about this issue? I use material-ui-icons in my navbar, and so i have a server side rendering issues: Warning: Prop And my design is fucked off >< I import all from /es, same for withStyles. The only way to fix that for me is to update the createSvgIcon.js to use the /es SvgIvon. This is really strange because i import from material-ui/icons/es/* so why this function don't use the es SvgIcon ? |
@CocoJr You need to use the |
@oliviertassinari look my edit :)
I do just this update and all works perfectly .... |
I'm not surprised. Are we good then? |
yes, i have an other "bugs" of SSR:
But this is linked to react only :) My design works fine and no mismatch bewteen my SSR and my client. I don't know how to fix that in your repo :/ EDIT: All is fixed with that. I use temporally |
Giving more thought to the issue, I don't think that we can move forward with this approach. It would require the duplication of the icons, something that makes a 30MB package a 50MB package with 10k files. It's often making yarn timeout. The only path forward I can think of is publish a second package like |
I don't think |
@dantman Oh, this is smart. Thanks for sharing this great workaround! |
Here's the code for // Force imports of packages like lodash to use the *-es package variant
new webpack.NormalModuleReplacementPlugin(/^lodash(\/|$)/, resource => {
resource.request = resource.request.replace(
/^(@[^/+]+\/[^/+]+|[^/+]+)(\/.*)?$/,
'$1-es/$2'
);
}),
// Force imports of packages like @material-ui/core to use the /es versions
new webpack.NormalModuleReplacementPlugin(
/^@material-ui\/core(\/|$)/,
resource => {
resource.request = resource.request.replace(
/^(@[^/+]+\/[^/+]+|[^/+]+)(?:\/es)?(\/.*)?$/,
'$1/es$2'
);
}
), It already works with lodash-es, so IMHO an |
@dantman Sure, but for MUI, it doesn't address the issue of shipping both ES5 and ES6 versions of icons, which leads to increased lib size, and opens doors for duplication. And the latter only unless you rewrite the import paths explicitly, as you did, but even then you're targeting ES6. This won't work if you need to support IE11, or else you'd have to transpile MUI with @oliviertassinari From what I understand, |
If the ES6 code is in a separate
We target IE11. We do transpile MUI using preset-env. And we have separate modern and legacy bundles. So the modern bundle gets few polyfills and transforms, making it much smaller. This is still advantageous even for legacy bundle that supports IE11 because the |
@alex996 The |
material-ui-icons uses
material-ui/SvgIcon
, which usesmaterial-ui/styles/withStyles
, which creates a static generateClassNames, resetting the static rule counter.In an app that is otherwise using ES6 material-ui, including
material-ui/**es**/styles/withStyles
, this results in the counter being reset. If that happens before any JssProvider is set up, all good. But if it happens afterward, as is likely with chunked production client code, it resets the rule counter late, resulting in className skewage in hydration of the SSR rendering.A workaround in client code is to force early loading of
material-ui/styles/withStyles
in the browser, e.g., in TypeScript:The text was updated successfully, but these errors were encountered: