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.

[material-ui-icons] load-order problem with SSR and ES6 use of material-ui; needs ES variant?

See original GitHub issue

material-ui-icons uses material-ui/SvgIcon, which uses material-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:

import {default as wrongWithStyles} from 'material-ui/styles/withStyles'
const _fooWrongStyles = wrongWithStyles

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
dantmancommented, Sep 1, 2018

Here’s the code for lodash-es and @material-ui/es.


	// 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 @material-ui/icons-es would probably work out fairly well.

2reactions
dantmancommented, Sep 1, 2018

The only path forward I can think of is publish a second package like @material-ui/icons-es. But following #10649 (comment), it only works if you don’t rely on third-party libraries using Material-UI.

I don’t think @material-ui/icons/es and @material-ui/icons-es are any different in that regard. I use the MUI es/ folder fine even with 3rd party libraries using a WebPack config to make everything use es/.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[material-ui-icons] load-order problem with SSR and ES6 use ...
In an app that is otherwise using ES6 material-ui, including material-ui/**es**/styles/withStyles , this results in the counter being reset.
Read more >
Material Icons - Material UI - MUI
The @mui/icons-material package depends on @mui/material , which requires Emotion packages. If you don't use Material UI in your project yet, install the...
Read more >
@material-ui/icons | Yarn - Package Manager
@material-ui/icons. This package provides the Google Material icons packaged as a set of React components. Installation. Install the package in your project ...
Read more >
How can I import Material UI icons?i met some problems using ...
Material UI doesn't provide icons from "@material-ui/icons" any more. Instead, you need to import icons from "@mui/icons-material".
Read more >
CHANGELOG.md - TINMAN
chainPropTypes issue ### `@material-ui/styles@v3.0.0-alpha.6` - Fix utils. ... clarity around the usage of font icons (#13628) @JosephMart - [docs] Add ...
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