Skip to content
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

Mui components generating too much style tags #30892

Closed
2 tasks done
darman96 opened this issue Feb 3, 2022 · 20 comments
Closed
2 tasks done

Mui components generating too much style tags #30892

darman96 opened this issue Feb 3, 2022 · 20 comments
Assignees
Labels
package: material-ui Specific to @mui/material status: waiting for author Issue with insufficient information

Comments

@darman96
Copy link

darman96 commented Feb 3, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Since migrating to Material-UI 5 Some MUI Components (especially Inputs) are generating a huge amount of style tags inside the html head which heavily impacts the performance of our app. It seems that those styles are duplicated for every instance of that component.
Also, I don't see why styles of one component have to be in multiple style tags instead of being grouped into one.

Expected behavior 🤔

Grouping styles in one style tag and reusing classes for multiple component instances.

Steps to reproduce 🕹

I prepared a CodeSandbox example.
If you look at the page source you can see the style tags inside <head> increase proportional with the amount of list items.

Context 🔦

Just to clarify our situation, we are currently developing a web app which displays a lot of data inside a table.
So far we used Mui4 and just fixed a performance issue where using dynamic styles inside our table cells lead to 100s of styles being generated. After switching to static styles performance improved greatly but since I migrated to Mui5 it's just as bad as before with dynamic styles.

Your environment 🌎

See CodeSandbox

@darman96 darman96 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 3, 2022
@michaldudak michaldudak added bug 🐛 Something doesn't work package: material-ui Specific to @mui/material and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 8, 2022
@mnajdova
Copy link
Member

mnajdova commented Feb 9, 2022

@darman96 could you provide two examples (v4 vs v5) where it is visible that there are perf regressions? Dynamic styles should be way faster with v5, this was one of the main reasons why we moved to emotion (vs JSS used in v4). I can't see notable perf issues on the Codesandbox that you've shared.

Also, I don't see why styles of one component have to be in multiple style tags instead of being grouped into one.

Actually, emotion merged all styles under one class name. The other classes that you see exist so that people can target those and add overrides, they do not contain any styles associated with them.

In addition, as far as I can see the classes are re-used, for example

image

@mnajdova mnajdova added status: waiting for author Issue with insufficient information and removed bug 🐛 Something doesn't work labels Feb 9, 2022
@darman96
Copy link
Author

I'll try to prepare some examples later today if I got time.

@yuliia-liaison
Copy link

Hi, we've started using MUI System on the project after migrating from v4 to v5 and have faced the same issue with many style tags included.

In general, one style tag includes only one CSS selector.

image

@mnajdova If there's some way how to combine styles please let us know.

@vivitali
Copy link

Also face that issue on early stage of the project. Any idea how to reduce it?
image

@darman96
Copy link
Author

darman96 commented Feb 17, 2022

Sorry for the delay, I have a new example Sandbox.
The performance difference in this case isn't that drastic but our table rows are somewhat more complex.

Edit: We changed our TableCells to only render an input field while they are interacted with as a fix.
But none the less those Textfields should not generate so many global styles.

Edit 2: Almost forgot. The performance issue is noticable when skipping through pages of the Tables.
For the Mui5 version the delay of switching pages increases with increased rows per page while the Mui4 version stays consistent.

@github-actions
Copy link

Since the issue is missing key information, and has been inactive for 7 days, it has been automatically closed.
If you wish to see the issue reopened, please provide the missing information.

@yuliia-liaison
Copy link

@michaldudak @mnajdova Please reopen the ticket since it's not resolved.

@mnajdova
Copy link
Member

mnajdova commented Mar 2, 2022

Looks like the issue is related to #28070 (comment) (rendering menu inputs causes generating manu global styles). For allowing developers to improve perf for scenarios like this, this PR #29213 introduced a new prop for disabling the automatic generation of global styles, you just need to make sure to add the global styles once in the top of your application. You can follow the instructions in the PR. Let me know if this solves your issue.

@LvChengbin
Copy link

image

@mnajdova
Copy link
Member

Has anyone checked #30892 (comment) and the PR linked to it? Posting new screenshots is not helping anyone.

@bcattonsimply
Copy link

I have also ran into this issue in a similar case, in a form containing many textfield components. I am also seeing a significant performance degradation when migrating from v4 to v5 in situations where I am rendering ~180 textfield components in a large form. In my case, rendering 180 textfield components generated over 3000 <style> tags! Switching between tabs in my app, each of which contained up to 180 textfields was where I saw the worst performance. I tried to disable the global injection of styles which I saw earlier in this thread but that did nothing to solve my issue, because the out of the box textfield component generates a huge number of <style> tags by itself.

I styled my textfield components with the sx prop and the styled api and chose not to use the theme styleOverrides as in my opinion they are not as easy to read for someone not familiar with MUI.

If anyone knows how to solve this problem please let me know!

@mnajdova
Copy link
Member

@bcattonsimply would be great if you can share a codesandbox with a similar reproduction to what you have in your app. It would help us debug the issue.

@tamdc
Copy link

tamdc commented Sep 20, 2023

Has anyone solved this issue yet?

@d-vorobyov
Copy link

This is not about TextField only
image

@ericmillsio
Copy link

For my project, I thought I had this issue too, but it was only in development and does not show up in production FYI.

@silviaphungky
Copy link

any update about this issue?
I am facing same problem

@Kepron
Copy link

Kepron commented May 12, 2024

I am facing same problem too. My current project looks like this (production)

image

@Kepron
Copy link

Kepron commented May 27, 2024

For my project, I thought I had this issue too, but it was only in development and does not show up in production FYI.

How? This problem also appears in my production. Can i see your next.config or any settings file?

@piyush52dixit
Copy link

Same here Facing the same issue in Developement and Production env.

For my project, I thought I had this issue too, but it was only in development and does not show up in production FYI.

How? This problem also appears in my production. Can i see your next.config or any settings file?

@Kepron
Copy link

Kepron commented Jul 26, 2024

Same here Facing the same issue in Developement and Production env.

For my project, I thought I had this issue too, but it was only in development and does not show up in production FYI.

How? This problem also appears in my production. Can i see your next.config or any settings file?

I solved this problem. If you using Nextjs, here is the solution link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: material-ui Specific to @mui/material status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests