A way to clean up unused styles in <head> that emotion create
See original GitHub issueFrom what I understand the styles that emotion adds to <head> are never cleaned up and the list of styles grow unbounded.
This can be an issue with single page apps that have components that use styles that are parametrized like this:
function Foo() {
const [counter, setCounter] = React.useState(0);
React.useEffect(() => {
setInterval(() => {
setCounter((p) => p + 1);
}, 1000);
}, []);
return <Box sx={{ width: counter }} />;
}
By rendering <Foo/> the number of styles will grow and remain in <head> even if Foo is unmounted. To my knowledge there is no way to remove the styles that are unused.
Could we add a way to help SPAs to manage styles/resources?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How Do You Remove Unused CSS From a Site?
To clean CSS with multiple pages just use that tool for all pages with different layouts. Then merge all exported CSS files to...
Read more >CSS Architectures: Principles of Code Cleanup - SitePoint
Denise Jacobs goes through some basic exercises in cleaning up CSS code, before going on to improve code with the latest best practices....
Read more >4 Ways to Remove Unused CSS - Bits and Pieces
This is a tool that is very effective in cleaning out unused css styles. The cool thing with purgecss is that it can...
Read more >How To Declutter Your Mind: 10 Practical Tips You'll ... - Forbes
Eliminating unnecessary thoughts, fears and concerns help reduce stress, boost self-esteem and free up mental space. Monitor your thoughts ...
Read more >Why We're Breaking Up with CSS-in-JS - DEV Community
While I have not measured this, I believe one of the most significant factors in how Emotion performs is whether style serialization is ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This was already discussed in https://github.com/emotion-js/emotion/issues/2473 and https://github.com/emotion-js/emotion/issues/488
TL;DR: There hasn’t been any strong evidence that suggests growing number of styles is an issue. The cases that do create a larger number of styles over time can usually use a different implementation.
I haven’t look into detail about this but it seems like issue related to style-engine (emotion). I suggest you create this issue on emotion repo and tag me to see what we can do about this.