-
-
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
makeStyles
API creates thousands of <style>
tags synchronously
#16756
Comments
Related to #16180. |
@Swatinem I wouldn't do that! Have you considered not using @material-ui/styles, using for instance, styled-components? The main reason for the existence of @material-ui/styles is to avoid the need to duplicate a CSS-in-JS runtime. If you are OK with +14 kB gzipped, you should use styled-components instead. |
We have discussed this internally today, @priscilawebdev will evaluate moving our uses to styled-components, and keep an eye on how the performance changes… |
@Swatinem I don't think these style tags are actually empty. When you create a |
@wereHamster oh nice, I didn’t know… Then it becomes:
So most of these are single rule stylesheets.
Most of the rules however are unique. That kind of surprises me…
So there is no deduplication going on … Lets investigate further…
So we are down to Well not only do we have all these mostly duplicate rules injected into the head, they also have uselessly unique classnames, which defeats the whole purpose style sharing via classes, and blows up the generated html as well… |
makeStyles
API creates thousands of empty <style>
tags synchronouslymakeStyles
API creates thousands of <style>
tags synchronously
@Swatinem did you ever get an explanation for this? Did you ultimately move to styled components to improve performance? |
I have moved on to different things by now, maybe @treylon can give you an answer. |
@tlambrou We ultimately moved back to styled components and stopped investigating further. |
Duplicate of #17370 |
We use hooks with dynamic props extensively.
I might even say it completely got out of hand, our codebase basically has hooks for every CSS property you can set, for example:
However, this extensive usage is super bad for performance, as it seems the hooks API creates and injects 1) empty styles 2) synchronously.
The profile starts here:
https://github.com/mui-org/material-ui/blob/d4c7c0586bb7853705ed1337f3f8392eb892a1bc/packages/material-ui-styles/src/makeStyles/makeStyles.js#L225
and ends up here:
https://github.com/cssinjs/jss/blob/0b17c5d9717141565e466ea0dafdf3ccbe86df5a/packages/jss/src/DomRenderer.js#L335
However, up to 99% of the
<style>
tags end up empty:Possibly related to #16111 maybe?
Expected Behavior 🤔
Current Behavior 😯
<style>
tags created by jss are emptyuseSynchronousEffect
and do DOM thrashingSteps to Reproduce 🕹
Link: https://www.eversports.style/design/icons
Just loading the page takes ages, navigating between
Typography
andIcons
sections takes in the order of 2-3 seconds, on a beefy desktop browser.sorry for not providing a reduced testcase, but meh, its quite clear whats going on.
Context 🔦
Your Environment 🌎
The text was updated successfully, but these errors were encountered: