-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Destructured imports for @material-ui/icons slow down live reloading #12422
Comments
@nikoladev This is sort of alluded to in the icons package README where import options are discussed
But we could repeat that in the main docs page and be more explicit about the performance implications. |
@mbrookes How do you think we can improve the documentation? I'm having a hard time seeing how we can do better. The section you linked looks enough to me. The more code you use the slower everything is. |
@oliviertassinari That's only in the README. I've added it to the main docs along with a note about HMR performance in both. |
Here's a js code shifter for those wishing to use full path imports > jscodeshift ./src -t ./mui-icons-import-shifter.ts --extensions=tsx --parser=tsx -d -p //mui-icons-import-shifter.ts
export default function (
fileInfo: FileInfo,
api: API,
options: Map<string, any>
) {
const j = api.jscodeshift;
const root = j(fileInfo.source);
root
.find(j.ImportDeclaration, { source: { value: "@mui/icons-material" } })
.forEach((importDeclaration) => {
j(importDeclaration).replaceWith(() => {
const importDeclarations = [];
importDeclaration.node.specifiers.forEach((memberSpecifier) => {
if (memberSpecifier.type === "ImportSpecifier") {
const module = memberSpecifier.imported.name;
const modulePath = `@mui/icons-material/${module}`;
importDeclarations.push(
j.importDeclaration(
[j.importDefaultSpecifier(j.identifier(module))],
j.literal(modulePath)
)
);
}
});
return importDeclarations;
});
});
return root.toSource({ quote: "single" });
} |
Got this error while trying to run your jscodeshifter script : |
Ever since version 2 of
@material-ui/icons
my live reloading is reaaaaaally slow (from less than a second to more than 5 seconds). The fix for this is to change how I import the icons:Slow:
Quick:
I guess a quick fix would be to mention somewhere in the docs that destructured imports slow down live reloading in certain cases.
(I've bootstrapped my project with
create-react-app
)Expected Behavior
Quick live reloading (<1 second)
Current Behavior
Slow live reloading (>5 seconds)
Steps to Reproduce
Here's the code that I changed that fixed this issue for me:
(Slow live reloading)
(Quick live reloading)
Context
Now that I've figured out how to fix this it isn't really a problem for me. But others who don't know about this might be stuck trying to figure out why their live reloading is slow all of a sudden.
Your Environment
The text was updated successfully, but these errors were encountered: