shadycss icon indicating copy to clipboard operation
shadycss copied to clipboard

Edge <= 14 unimported CSS variables and mixins not working

Open jehna opened this issue 9 years ago • 7 comments

Description

In Edge browser the CSS variables nor mixins do not work by default. They only work if they are applied via html imported <custom-style>.

How to reproduce

  1. Clone https://github.com/jehna/polymer-shadycss-var-calc-bug
  2. Install dependencies & run project
  3. Open http://localhost:8081/ in Edge browser

Behaviour

Only the first two <div>s are green, the three other divs are red.

Expected behaviour

All divs should be green, as all their backgrounds are set to green via css variables.

Impacted browsers

  • [x] Edge <= 14
  • [ ] Edge >= 15
  • [ ] Chrome
  • [ ] Safari
  • [ ] Firefox

jehna avatar Apr 18 '17 12:04 jehna

Update: This issue also applies to CSS mixins.

Updated the sample repository to also include mixins.

jehna avatar Apr 19 '17 10:04 jehna

Update: Only applies to Edge <= 14. Edge 15 seems to support CSS variables.

jehna avatar Apr 19 '17 11:04 jehna

This is the expected behavior: the reason custom-style exists is to shim document-level styles. So neither custom properties or custom mixins are supported on non-native browsers unless they're defined inside an element's template or in a custom-style. I think that's not as clear in the 2.x docs as it was in the 1.x docs, so we should probably fix that. (@katejeffreys maybe open a docs ticket for this?)

The :root selector isn't supported at all in 2.0. See: https://www.polymer-project.org/2.0/docs/upgrade#shadow-dom-styles. (I'm not sure why the :root in custom-style is working ATM, but it probably shouldn't be.

arthurevans avatar Apr 19 '17 17:04 arthurevans

As @arthurevans says, you shouldn't use :root but rather html for custom-style and either :host or :host > * for inside of a shadowroot.

ShadyCSS does transform :root into the correct selector for backwards compatibility, but it might be a bit buggy, as you are finding.

Here is a Plunker reproduction of your example using html and :host > * where appropriate: http://plnkr.co/edit/4Nb6sxmEmMwzVs2gKae1?p=preview

The #doesnotwork div is not green because the CSS Custom Property shim that is used in Edge 14 cannot process setting a variable in any selector that does not start with :host.

dfreedm avatar Apr 19 '17 18:04 dfreedm

Is that last one a new limitation, @azakus? I don't recall it from 1.x. We should definitely add it to the docs, since Edge 14 is one of the last places we're using a custom properties shim...

arthurevans avatar Apr 19 '17 18:04 arthurevans

@arthurevans it is in the fine print here: https://www.polymer-project.org/1.0/docs/devguide/styling#custom-properties-shim-limitations, under "Inheritance limitations"

Unlike normal CSS inheritance which flows from parent to child, custom properties in Polymer's shim can only change when inherited by a custom element from rules that set properties in scope(s) above it, or in a :host rule for that scope.

dfreedm avatar Apr 19 '17 18:04 dfreedm

Hmm... I thought that included rules that matched a polymer element, that is:

<dom-module id="host-el">
  <template>
    <style>
      child-el { --some-value: blue; } 
   </style>
   <!-- where child-el is a Polymer element -->
   <child-el></child-el>
  </template>
  ...
</dom-module>

arthurevans avatar Apr 19 '17 19:04 arthurevans