[styles] Style nodes leaking when switching global theme in StrictMode
See original GitHub issue- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
I have been created a sandbox for this bug here https://codesandbox.io/s/clever-black-shc9b?file=/src/index.tsx.
For nested <ThemeProvider/>
s rendered in <React.StrictMode/>
. The style nodes created by the inner theme will be leaking when switching the outer theme alternately.
Steps to Reproduce 🕹
Steps:
- Go to https://codesandbox.io/s/clever-black-shc9b?file=/src/index.tsx
- Open Chrome dev tools and inspect the
<head/>
node of the browser panel - You will see for every 2 seconds a new style node was added continuously
- If you remove the
<React.StrictMode/>
node then this buggy behavior will be gone
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Duplicated MuiButtonBase (and others) in <style> elements
You can change the class name generation to output non-global ... is: Style nodes leaking when switching global theme in StrictMode #20708.
Read more >How To Style React Components | DigitalOcean
Now add the styles. First, open the CSS for the Alert component: nano src/components/Alert/Alert.
Read more >Why We're Breaking Up with CSS-in-JS - DEV Community
Our New Styling System. After we made up our minds to switch away from CSS-in-JS, the obvious question is: what should we be...
Read more >Strict Mode - React
StrictMode is a tool for highlighting potential problems in an application. Like Fragment , StrictMode does not render any visible UI.
Read more >Let's code: global styles variations in block themes
In this session, we'll be creating a new block theme, and creating a few new Global Style variations for it, to ship with...
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 FreeTop 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
Top GitHub Comments
An update, we have now made enough progress with the new
@material-ui/styled-engine
package in v5 to move toward a progressive removal of the@material-ui/styles
package (based on JSS). The current plan:sx
prop +styled()
API). We might for instance, invest in the documentation for using react-jss that has more or less the same API. We could also invest in an adapter to restore the previous API but with emotion, not JSS.withStyles
/makeStyles
API).This was made possible by the awesome work of @mnajdova.
Ok I found out that useSynchronousEffect is used because it’s handler takes care of creating and attaching the stylesheets, which is necessary for the following code to get the classes. However I think there is a better solution to solve the issue of getting class names for rendering of the component.
To solve this, I would propose splitting this into two steps:
I did some testing by directly modifying the code in makeStyles.js and could prove that doing it this way fixes the issue with StrictMode.
PS: Why was the important label removed? I think this is actually quite the important move in order to allow developers to work towards future-proof applications by using StrictMode