-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
classes
styles don't override default when using @emotion/react
#28045
Comments
I have observed this same behaviour. Initially I couldn't even see where my styles were being applied, but eventually I noticed them merged into one giant rule. I have observed similar behaviour with className too. This is a departure from v4, I believe. In the sandbox example above, the combined style I will add, it also makes it harder to debug custom styles, because you can't easily tell what's coming from where. |
In order for emotion to consider how the classes should be appended in the head, it requires you to use the I've played a bit with the sandbox and I saw that the Anyway, I don't think we can do much with how the classes are appended (note that they can be generated in a different manner - maybe with static css or with any other css in jss solution), so it is up to the developers to ensure that those will be injected after the default styles coming from Material-UI. We can correctly predict how the styles will be merged if some of the internal APIs are used ( Anyway, I will spend some more time on this tomorrow to see if we can have some quick win maybe. I am open for ideas of how we can improve this. |
Hi @mnajdova,
Then, and only in this very specific configuration, you guys should be able, using
PS: This is not something that I need fixed for |
Thanks a lot for the clarification @garronej I will anyway spend some more time tomorrow, my biggest worry is that |
I've spent some more time on this. I don't think it's worth solving. The reasons are the following:
I will leave the issue open, to see if other developers will have the problem. |
Hi @mnajdova, CSS injection priority is not that easy to configure especially when SSR is involved. In the current state of things, to get everything working as expected, users have to:
That said the three points you made are valid as well. It's a tough call, I'm glad I am not the one having to make it. 😁 |
Also for user that would like to use
I think, if you chose not to address this issue, you'll have to state in the documentation that it isn't possible to use |
I am a but confused with this statement. In the codesandbox that you shared, when using In v4 as far as I know it doesn’t matter if you provide the classes generated from makeStyles to the Anyway, more detailed example of v4 vs v5 that proves this would be helpful, as I really don’t think using classes generated by makeStyles take presedence based on whether they are passed to |
Forgive me🙏, I am quite embarrassed, this damage my credibility quite a bit, as I was preparing the sandbox I realised that your are in-fact right. It's something that was reported to me by one user, I assumed it was true. I should have tested it before submitting it here. The other points I made still stands though. |
Ok, glad we are on the same page :) Will report back tomorrow after I spend some more time on this :) |
I won't do any changes at this moment and wait to see if there will be more activity on the issue. |
classes
props and in the context of a shared emotion cache.classes
styles don't override default when using @emotion/react
@mnajdova, that's fine with me. I updated the issue so it can be easily found by people that would be affected. Best regards |
Hi @mnajdova ,
I understand that this is a very hard to address issue but I also think it is pretty critical. Best regards and congratulations for being able to hire again. MUI is a true success story. |
Thanks for the bump @garronej I am adding it to my list for next week. |
That's great to hear. I am very motivated because there is something else I forgot to mention. Right now, I need specific instructions to instruct users how to setup SSR. Best regards, |
We would need to export an If you are interested to give this a go, feel free to, I can help wtih the |
Hi @mnajdova, thanks for your answer,
Precisely!
Yes, I can use
The great thing is that we won't need to change anything beside exposing
Yes! I am very interested, If you are OK, we can follow the discussion on the basis of a PR? |
Yes, let's start with a PR and see what the final API would look like |
Addressed in #32067 |
Abstract
Who it's affecting
This issues only affect users that uses
@emotion/react
to write their custom styles.What is the issue
The styles provided to the
classes
property of MUI components don't take priority over the internal styles and there is no way around it.Original issue
Hi,
Following up with 27945 I think there is (arguably) a unexpected behaviour in the way the
classes
prop is handled when the user is using emotion and the same cache that material-ui is using.Current Behavior 😯
The default style have the priority hover style provided in
classes
. (in a specific context described below)Expected Behavior 🤔
The styles explicitely provided by users in
classes
should always overwrite the defaults.Steps to Reproduce 🕹
sandbox
Steps:
!important
line 21Context
This issue is not related to SSR and it is not specific to
tss-react
.My investigation
Best,
The text was updated successfully, but these errors were encountered: