-
-
Notifications
You must be signed in to change notification settings - Fork 27k
CSS Variables #1283
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
Comments
I don't know enough about CSS variables but from discussion in #130 it seemed like they're not really "future proof" because they work differently than they would in browser. This seems like a no-go but maybe I misunderstand. Can you elaborate? |
#130 is a massive discussion, so TLDR, from the postcss-custom-properties repo:
But assuming all you want to do is define some custom props on // ...
"scripts": {
// ...
"postbuild": "postcss --use postcss-custom-properties --replace build/**/*.css"
} |
I've been following the discussion on CSS in CRA. I have previously used Sass, CSS Modules and styled-components. I greatly admire the pragmatic approach favoured by CRA, and I'm looking forward to seeing the result of a closer look at how CSS should be handled (as mentioned). For the record, variables accessible in both CSS and JS would be amazing (CSS Modules offers this, I think). |
I would like to use CSS variables in my CRA project and have them polyfilled post processing since this feature is not support by many browsers. |
Thanks for the tip @benknight! |
I'm still confused about how https://github.com/postcss/postcss-custom-properties works. It says it only can handle a subset of the spec. So what happens if you use something more dynamic than it supports? Does it emit invalid output? Silently keep the syntax without transforming it? Warn? Error? |
@gaearon I made up a little demo to check how it handles dynamic cascading variables, and here's an example before & after: Before:root {
--first-color: #488cff;
--second-color: #ffff8c;
}
#firstParagraph {
background-color: var(--first-color);
color: var(--second-color);
}
#secondParagraph {
background-color: var(--second-color);
color: var(--first-color);
}
#container {
--first-color: #48ff32;
}
#thirdParagraph {
background-color: var(--first-color);
color: var(--second-color);
} After#firstParagraph {
background-color: #488cff;
color: #ffff8c;
}
#secondParagraph {
background-color: #ffff8c;
color: #488cff;
}
#container {
--first-color: #48ff32;
}
#thirdParagraph {
background-color: #488cff;
color: #ffff8c;
} So you can see it just left the |
What about this concern? #130 (comment) |
@gaearon right so again the giant caveat with postcss-custom-properties is that dynamic cascading is not supported, so its primary use case is for setting static, global variables on In the unfortunate case that an author uses cascading dynamic variables anyway, despite this caveat, the results would appear as expected in browsers that support CSS custom props, and likely broken in browsers that do not. In the comment you linked, it appears he's advising setting the Input:root {
--foo: green;
}
header {
--foo: red;
}
h1 {
color: var(--foo);
} Outputwith
|
From what I’ve gathered from the MDN compatibility table, CSS variables have been in modern browsers since as early as 2015 and as recently as mid-2017.
When this issue was opened in 2016, it was pretty fair to assume that a large portion of an app’s user base would be on an unsupported browser. Given that we’re a year+ out from major browsers adding CSS variables, is it a good idea to backfill support for this feature given there exists at least one (dynamic cascading) pretty large inconsistency with the actual spec? I feel this could introduce unexpected behavior in users’ apps, especially versus if they added postcss-custom-properties themselves, after identifying a need for its inclusion and understanding its inherent tradeoffs. |
Yeah I suppose by now it’s not as necessary. We’ll also include optional Sass and CSS modules support in the next release for people who feel they need them. So I think this is sufficient. |
IE11 will not work. I think that this issue should somehow still be resolved. I am trying to fix some issues I have with IE11, where this is related. To test it I will have to build and use the postcss solution to see if my issue have been resolved. It would be awesome if it was possible to use CSS-variables as #1283 (comment) describes |
Hi, I have found create-react-app to be a wonderful asset to rapidly setting up and maintaining react apps. I found myself, however, forking create-react-app in order to inject postcss-cssnext to add css variables. I know this has been discussed before ( #130 ) and rejected since cssnext was considered too unstable to be supported by CRA.
I feel, however, that css variables are something that most developers would find useful (and nearly essential when designing complex apps). I would rather avoid having to resort to a beefy solution like SASS or Less when future-proof css will work just fine. I am also not a fan of CSS-in-JS solutions. Further, I know that Facebook itself also uses CSS variables in some of their React apps.
Would you be open to reconsidering CRA support for css variables?
The text was updated successfully, but these errors were encountered: