-
-
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
compiled css precedence #16609
Comments
@Luucky Please provide a full reproduction test case. This would help a lot 👷 . |
@oliviertassinari Here's a link for the DEV EXAMPLE: https://codesandbox.io/embed/create-react-app-36pid Notice how space between buttons disappears. The margin of |
The CSS specificity of import '../Button'; // So we don't have any override priority issue. to get the CSS injection order right. The alternative is to increase the specificity to 2. I like this idea, it would make use component agnostic (work with everybody, not just our Button) diff --git a/packages/material-ui/src/CardActions/CardActions.js b/packages/material-ui/src/CardActions/CardActions.js
index ee57f0120..91b7c574a 100644
--- a/packages/material-ui/src/CardActions/CardActions.js
+++ b/packages/material-ui/src/CardActions/CardActions.js
@@ -2,7 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import withStyles from '../styles/withStyles';
-import '../Button'; // So we don't have any override priority issue.
export const styles = {
/* Styles applied to the root element. */
@@ -13,7 +12,7 @@ export const styles = {
},
/* Styles applied to the root element if `disableSpacing={false}`. */
spacing: {
- '& > * + *': {
+ '& > :not(:first-child)': {
marginLeft: 8,
},
},
diff --git a/packages/material-ui/src/DialogActions/DialogActions.js b/packages/material-ui/src/DialogActions/DialogActions.js
index 6fb342f5c..458c61350 100644
--- a/packages/material-ui/src/DialogActions/DialogActions.js
+++ b/packages/material-ui/src/DialogActions/DialogActions.js
@@ -2,7 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import withStyles from '../styles/withStyles';
-import '../Button'; // So we don't have any override priority issue.
export const styles = {
/* Styles applied to the root element. */
@@ -15,7 +14,7 @@ export const styles = {
},
/* Styles applied to the root element if `disableSpacing={false}`. */
spacing: {
- '& > * + *': {
+ '& > :not(:first-child)': {
marginLeft: 8,
},
},
diff --git a/packages/material-ui/src/ExpansionPanelActions/ExpansionPanelActions.js b/packages/material-ui/src/ExpansionPanelActions/ExpansionPanelActions.js
index 5451c6387..2e3f9f179 100644
--- a/packages/material-ui/src/ExpansionPanelActions/ExpansionPanelActions.js
+++ b/packages/material-ui/src/ExpansionPanelActions/ExpansionPanelActions.js
@@ -2,7 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import withStyles from '../styles/withStyles';
-import '../Button'; // So we don't have any override priority issue.
export const styles = {
/* Styles applied to the root element. */
@@ -14,7 +13,7 @@ export const styles = {
},
/* Styles applied to the root element if `disableSpacing={false}`. */
spacing: {
- '& > * + *': {
+ '& > :not(:first-child)': {
marginLeft: 8,
},
}, cc @eps1lon as you were advocating for removing the import (tree-shaking) @Luucky I can't explain the behavior of the deployment. Something is wrong in the bundling pipeline independently from my previous comment about CSS specificity. |
I also had a similar thing happen when I tried the following:
|
@Luucky This one is expected. Unless you control the import order, the CSS win is unpredictable. |
i have the same issue with @Luucky |
I'm running into an issue that may be related. If not, I will open another issue. When building my react app in production mode ( it seems the production mode is the issue, but I do not know where to begin looking. |
The same issue exists with .MuiCardActions-spacing. I just ran into this issue setting up server rendering. Server rendering has them in the right order and React.render renders them in the right order but React.hydrate results in .MuiButtonBase-root being added after .MuiCardActions-spacing which makes the buttons drop the left margin after hydrate. |
@nickpalmer this symptom might hide another issue. |
@oliviertassinari After further investigation we have the exact same problem on our staging environment, we just never noticed. It thus has nothing to do with hydrate and everything to do with how create-react-app is compiling things for production. |
Fixed similar behaviour with webpack setting
https://webpack.js.org/configuration/optimization/#optimizationsideeffects |
@dva I can confirm that this resolves the issue. |
@nickpalmer final build getting bigger btw. |
it works correctly if we disable SSR. in case of SSR few styles are picked from server css file. |
While I can no longer reproduce the issue on Codesandbox, CRA and Next.js, I would propose that we move forward with #16609 (comment) so we can:
|
This comment has been minimized.
This comment has been minimized.
I have this exact same problem. EDIT: The workaround for me was adding {index: 1} in all of our components' withStyles, to ensure they were created after all the Material UI ones in production.
|
We also have the same problem using version 4.3.3. The workaround provided by @alexandrecanuto helped. It seems like Question: Why is this not set to 1 by default for makeStyles? Would this not help in future? |
This comment has been minimized.
This comment has been minimized.
Running into the same issue on 4.5.0 - we're not using SSR. Just a typical CRA. We have a shared In the image example below, the element is used like this: I would expect the This was working just a few days ago. We're seeing this even when running on localhost during development. My workaround in this specific case was to change: |
Is there any movement on this? I'm getting more and more areas where I'm having to use |
@Kizmar We would be happy to accept a pull request for #16609 (comment). |
Having the same issue as in #16609 (comment) - i.e. Dev != Prod A copy-paste: /* Dev: */
.MuiCardHeader-root {
 display: flex;
 padding: 16px;
 align-items: center;
}
.makeStyles-statusBarOk-276 {
color: #fff;
background: #4e698c;
padding-top: 8px;
padding-bottom: 8px;
}
/* Prod: */
.jss276 {
 color: #fff;
 background: #4e698c;
 padding-top: 8px;
 padding-bottom: 8px;
}
.MuiCardHeader-root {
display: flex;
padding: 16px;
align-items: center;
} So the style 276 gets wrong priority. Any ideas how to fix this? Is there a way to provide the priority? Material UI 4.2.0 |
When a project is compiled, the precedence of applied CSS rules changes.
Expected Behavior 🤔
Current Behavior 😯
Steps to Reproduce 🕹
marginLeft
of MuiDialogActions is overridden bymargin
of MuiButtonBaseYour Environment 🌎
The text was updated successfully, but these errors were encountered: