shadycss icon indicating copy to clipboard operation
shadycss copied to clipboard

Consider making `styleElement` force a host to shim custom properties

Open sorvell opened this issue 8 years ago • 1 comments

In order for shimmed custom properties to work correctly, (1) an element must have prepared its styles via prepareTemplateStyles, (2) must be in the DOM tree when it calls styleElement and (3) its host ancestors must already have called styleElement (shimming must go in tree order).

In some cases, an element will perform steps (1) and (2) in connectedCallback. However, this can introduce an ordering issue that prevents step (3) from working correctly.

  • host
    1. calls prepareTemplateStyles
    2. renders client DOM
      • client
        1. client calls prepareTemplateStyles
        2. client renders DOM
        3. client calls styleElement
    3. calls styleElement

In this case, shimming does not go in tree order. To address this, we could ensure that when styleElement is called and a styling host is found, it is forced to calculate custom properties (here) if they do not exist. This was previously done in Polymer 1.x and would help with this issue in lit-html: https://github.com/Polymer/lit-html/issues/655#issuecomment-442648651

sorvell avatar Nov 28 '18 23:11 sorvell

At https://github.com/webcomponents/shadycss/blob/master/src/scoping-shim.js#L342:

It seems like the minimal change we could make is to add after line 342:

if (!ownerProperties) {
  this._updateProperties(owner);
  ownerProperties = ownerStyleInfo.styleProperties;
}

sorvell avatar Nov 28 '18 23:11 sorvell