question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Support For CSS Variables

See original GitHub issue

Version

1.0.6

Reproduction

http://www.webpackbin.com/Vys62X0RZ

Steps to reproduce

Declare and use a CSS variable anywhere in a styled component.

Expected Behavior

Leading -should remain intact so that browsers can properly identify variable declarations.

Actual Behavior

the first - is being striped from the variable declaration causing browsers that support native CSS variables to view them as bad properties. If you go into dev tools and add the leading - back in, everything works as expected.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
geelencommented, Feb 24, 2017

The “polyfill” for css variables has some serious edge cases: https://github.com/MadLittleMods/postcss-css-variables#differences-from-postcss-custom-properties and the “Caveats” section below.

These all arise because it’s a PostCSS transform, and thus only has visibility into the CSS, not the DOM. This is part of the reason I am so opposed to postcss transforms being available in SC—they’re built for a different environment, and supporting/reproducing their limitations (or divergence from the specification as in this case) would weaken the whole proposal.

HOWEVER, if you’re feeling like a challenge 😉 Styled Components does have knowledge of both the DOM and the CSS rules, and so a true CSS custom properties polyfill is possible. I’ve had this in the back of my mind to implement for ages but it’s a lot of work. It would be amazing though!

In general, I’ve found that the combination of JS variables and inheritance using theming is everything I wanted CSS variables for anyway, so I haven’t missed them too much.

2reactions
geelencommented, Oct 17, 2016

Wow that’s a straight up miss on my part. Sorry! On Tue., 18 Oct. 2016 at 8:14 am Brian Hough notifications@github.com wrote:

Version

1.0.6 Reproduction

http://www.webpackbin.com/Vys62X0RZ Steps to reproduce

Declare and use a CSS variable anywhere in a styled component. Expected Behavior

Leading -should remain intact so that browsers can properly identify variable declarations. Actual Behavior

the first - is being striped from the variable declaration causing browsers that support native CSS variables to view them as bad properties. If you go into dev tools and add the leading - back in, everything works as expected.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/styled-components/styled-components/issues/108, or mute the thread https://github.com/notifications/unsubscribe-auth/AABa4NnvHpi5-PSlHkzPRkc_kqWP6j7gks5q0-U5gaJpZM4KZHOd .

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS Variables (Custom Properties) | Can I use... Support ...
CSS Variables (Custom Properties). - CR. Permits the declaration and usage of cascading variables in stylesheets. Usage % of. all users, all tracked ......
Read more >
Using CSS custom properties (variables) - MDN Web Docs
Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific ...
Read more >
A user's guide to CSS variables – Increment: Frontend
CSS variables are currently supported for 93 percent of users globally. CSS variables are currently supported for 93 percent of users globally. If...
Read more >
@supports with CSS Variables - CodePen
Adding Classes. In CodePen, whatever you write in the HTML editor is what goes within the <body> tags in a basic HTML5 template....
Read more >
Browser Compatibility of CSS Variables (Custom Properties)
CSS Variables (Custom Properties) on Chrome is fully supported on 49-106, partially supported on None of the versions, and not supported on 4-48 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found