[docs] Improving the sx prop documentation #42164
Labels
docs
Improvements or additions to the documentation
package: system
Specific to @mui/system
support: docs-feedback
Feedback from documentation page
Related page
https://mui.com/system/getting-started/the-sx-prop
Kind of issue
Missing information
Issue description
Currently, the
sx prop
documentation has no information about possible issues with memory usage when dealing with dynamic values.Background
I recently encountered a memory issue, which looked like a memory leak.
After long investigation, the reason was following component, that was created based on StackOverflow answer. The component was a custom
LinearProgress
that was rendered vertically.At first, I thought it was a memory leak in MUI component. However, after investigation, I found the following discussions:
If I understood correctly, the
sx
should not be used like this with a dynamic value. Using it like this causes more and more<style>
tags created in the page.As the
activeValue
is a constantly changing decimal value between 0 and 100, it has thousands and thousands of possible values in between. With multipleLinearProgressWithLabel
components , it eventially caused hundreds of thousands of generated<style>
tags added in the page<head>
.EDIT: I just noticed 30 minutes later, that in production version, there aren't multiple
<style>
tags. It seems they are combined in production. However the memory issue is the same in both production and development, it's just not visible in devtools DOM.This eventually crashed the web browser, as the application is a long-running kiosk app. Even when user doesn't touch the page at all. The web browser memory usage increases from 200mb to 2000mb in just around 24 hours.
I fixed this issue by recreating the component from scratch (and also used
style
prop instead).Suggestion
I suggest the sx prop page should be updated to warn about using dynamic values. As @markmanx commented in 2023, there seems to be no guidance for this.
sx
prop use cases.<style>
is kept in DOM and memory.sx
prop could cause heavy increase in memory usage in the long run, and in the worst case, a browser crash.style
prop should be used instead ofsx
in situations like this.I would also like to have a confirmation if my conclusion is correct.
Context
No response
Search keywords: sx, memory, memory leak, performance
The text was updated successfully, but these errors were encountered: