-
Notifications
You must be signed in to change notification settings - Fork 187
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
use of !important on all generated styles #25
Comments
Sure! It hasn't been causing problems for us at KA, but we would still like to get rid of it. We have it around so that any of our random global CSS styles won't end up accidentally overriding aphrodite ones. Have you been running into problems because of it? |
Awesome! Yeah, I figured that it was kept in for something along those lines. I've run into issues with it in a few strange cases, so here's my best shot at distilling those into a minimal example... |
One result of making everything !important is that styles passed to the In most cases, one would not need to use both the For example, we could imagine that function MyComponent({shouldAnimate, t}) {
const style = shouldAnimate ? createStyle(t) : {}
return (
<h1 className={css(styles.header)} style={style}>
Hello
</h1>
)
}
const styles = StyleSheet.create({
header: {
color: 'red',
fontSize: '10px',
},
})
function createStyle(t) {
return {
fontSize: `${t}px`,
}
} But since the font size is set to This could be solved by changing function createStyle(t) {
return {
fontSize: `${t}px !important`,
}
} but this feels like more of a temporary fix than a solution since it requires the developer to keep in mind this particular case where specificity is not as they would expect. Another work around is to create the StyleSheet based on function MyComponent({shouldAnimate, t}) {
const styles = createStyleSheet(shouldAnimate, t)
return (
<h1 className={css(styles.header)} style={style}>
Hello
</h1>
)
}
function createStyleSheet(shouldAnimate, t) {
return StyleSheet.create({
header: {
color: 'red',
fontSize: shouldAnimate ? '10px' : `${t}px`,
},
})
} but this suffers the overhead of running |
Anyways, I'm not certain where I stand on removing !important, but that's one example of where it hinders development. |
The |
@xymostech seems like a good option here would be to make the use of Would you be open to this approach? |
@jossmac I would be open to that approach. I'm not sure what a good way to add such a setting would be. Maybe a second argument to
|
@xymostech That api seems reasonable to me. Then if somebody wanted to disable // createStyleSheet.js
import {StyleSheet} from 'aphrodite'
export default function createStyleSheet(obj) {
return StyleSheet.create(obj, { important: false })
} and then import |
I'd be happy to put together a PR adding this options argument to |
@montemishkin Sounds good to me! |
I like exposing the |
Oh, also, hi @skitterm! 👋 Fancy meeting you here! (friends from school) |
Ok, so I did a quick test to see if gzipping made this not important on a size standpoint:
The original HTML file comes from the JavaScript Air site. In the |
So !important is 10% before gzip and 1.5% after? That's really not that bad. |
Yeah, I guess I was thinking more in terms of size. But I just realized that what I thought was |
Another reason to omit Edit: Also when browsers like Chrome display a little gripper in the bottom right corner of text areas to let the user resize them, the browsers resize the text areas by setting their width and height styles without |
I see that "Consider removing !important from everything." is listed under TODO in the README.
Perhaps this could be discussed here?
The text was updated successfully, but these errors were encountered: