-
-
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
[styled-engine] Add StylesProvider with injectFirst option #23934
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/mui-org/material-ui/dzfp3vav0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Find issues with remaining argos differences 😕
- This one is linked to the
<Box component={SvgIcon} />
pattern. Emotion does no longer win specificity with font-size. I guess it's an acceptable cost during the migration
-
This one seems to be the same issue.
clone
does no longer work. We could also say that it's fine considering it will be resolved once the migration is completed. -
The last one, with the drawer. The size of the drawer increase by 1px, the width of the border. It's box-sizing related. The regression tests are supposed to set
boxSizing: 'content-box',
. However, it's only now that it takes effect. Looks like a fix if you ask me. However, it also surfaces that these demos are not box-sizing invariant, not great. I would encourage we update the demos to force the box-sizing to border-box.
packages/material-ui-styled-engine/src/StylesProvider/StylesProvider.js
Outdated
Show resolved
Hide resolved
const head = document.head; | ||
injectFirstNode = document.createElement('style'); | ||
injectFirstNode.setAttribute('data-styled', 'active'); | ||
injectFirstNode.setAttribute('data-styled-version', '5.2.1'); | ||
head.insertBefore(injectFirstNode, head.firstChild); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Should we cleanup the style node after introduction?
- Did you consider
<StyleSheetManager target={}>
with a comment node as target?
Provide an alternate DOM node to inject styles
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it at some point but it didn't work, but it may have been related to other changes. Let me try again, it should definitely be cleaner than this. Also this doesn't work at the moment, the node is created but the styles are being added to a different node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found out why it wasn't working, but it is awkward. The node added has to be style tag with data-styled='active'
. Adding just a comment doesn't work. Basically, now it works, but we have first empty style tag, and then the one from styled-components.. Will leave it like this until we find a better alternative..
…ovider.js Co-authored-by: Olivier Tassinari <[email protected]>
@mnajdova We apply I was suggesting we do the same thing as with the core components but for the demos that are impacted, e.g. diff --git a/docs/src/pages/components/drawers/ResponsiveDrawer.tsx b/docs/src/pages/components/drawers/ResponsiveDrawer.tsx
index 9158b08af2..b4ddd17624 100644
--- a/docs/src/pages/components/drawers/ResponsiveDrawer.tsx
+++ b/docs/src/pages/components/drawers/ResponsiveDrawer.tsx
@@ -45,6 +45,7 @@ const useStyles = makeStyles((theme: Theme) =>
toolbar: theme.mixins.toolbar,
drawerPaper: {
width: drawerWidth,
+ boxSizing: 'border-box',
},
content: {
flexGrow: 1, Most of the time, it works fine. |
@oliviertassinari did the changes the only differences now are the ones which we could consider as an acceptable cost during the migration. ( We can update the examples for the Box to override another component where we won't have conflicts with the styles being applied, like Regarding the migration guide, should I update the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Hopefully, thats it, we have covered most of the challenges with the migration to emotion.
This PR adds
StylesProvider
withinjectFirst
option in both@material-ui/styled-engine
and@material-ui/styled-engine-sc
. TheStylesProvider
is exported from core asStyledEngineProvider
and used in the docs, codesandbox example template & the argosTestViewer
.The usage of this Provider will be necessary during the transition stage, where we have emotion components being overridden by JSS styles.
@material-ui/styled-engine-sc
's generated style tag being ignored