-
Notifications
You must be signed in to change notification settings - Fork 94
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
Stylesheet ordering bug with @mui/material and styled-components #547
Comments
Having a single So something is wrong with the order of insertions coming form mui/styled-components or our implementation of Good step to verify if the issue is on our side would be to |
@tajo so I've patched the stackblitz to log out the rule and index and I get the following: They key part is that it looks like the |
It's not in the spec but I guess it makes sense adding elements before existing index. https://github.com/tajo/ladle/blob/main/packages/ladle/lib/app/src/synchronize-head.tsx#L17 I think we just need to change |
I don't think changing For example here are the rules on our Ladle instance: The key bit is that rule I think to properly account for this we need to maintain a map of index to rule and regenerate all the stylesheets in the correct order after each insertion. What do you think? |
Are we sure that there is just one instance of styled-components / CSS-in-JS library doing these insertions? It's really strange it attempts to
Anyway, if that's the case we could store the index value in the existing |
@tajo there aren't multiple instances of styled-components on the page, it's because our |
@tajo any further thoughts on this issue? IMO having an option to disable the |
In my testing it didn't disable it because the ladle/packages/ladle/lib/app/src/synchronize-head.tsx Lines 76 to 99 in b4d67c1
Will raise a PR to fix it. |
Describe the bug
We are coming across a bug in Ladle where certain styles are being inserted into the
<head>
in the wrong order resulting in issues with styling. I've attached a reproduction with theChip
component from@mui/material
where the custom Chip component should have a red background colour.I think the issue is with the
SynchronizeHead
component and the fact that it's overriding theinsertRule
method on theCSSStyleSheet
prototype to create separate style tags in the head (styled-components only uses 1 style tag) and so the browser will treat the later style tags as more specific. I have verified this theory by commenting out the code that overrides theinsertRule
method in my localnode_modules
(not sure how to do it in stackblitz).Original PR: #488
Reproduction
https://stackblitz.com/edit/ladle-hzn2yy?file=src%2Fbasic.stories.tsx
Environment
The text was updated successfully, but these errors were encountered: