|
42 | 42 | } |
43 | 43 | if (this._template) { |
44 | 44 | this._styles = this._collectStyles(); |
| 45 | + // under shady dom we always output a shimmed style (which may be |
| 46 | + // empty) so that other dynamic stylesheets can always be placed |
| 47 | + // after the element's main stylesheet. |
| 48 | + // This helps ensure element styles are always in registration order. |
| 49 | + if (this._styles.length && !nativeShadow) { |
| 50 | + this._scopeStyle = styleUtil.applyStylePlaceHolder(this.is); |
| 51 | + } |
| 52 | + } |
| 53 | + }, |
| 54 | + |
| 55 | + _prepShimStyles: function() { |
| 56 | + if (this._template) { |
45 | 57 | // calculate shimmed styles (we must always do this as it |
46 | 58 | // stores shimmed style data in the css rules for later use) |
47 | 59 | var cssText = styleTransformer.elementStyles(this); |
|
50 | 62 | // do we really need to output static shimmed styles? |
51 | 63 | // only if no custom properties are used since otherwise |
52 | 64 | // styles are applied via property shimming. |
53 | | - var needsStatic = this._styles.length && |
54 | | - !this._needsStyleProperties(); |
55 | | - // under shady dom we always output a shimmed style (which may be |
56 | | - // empty) so that other dynamic stylesheets can always be placed |
57 | | - // after the element's main stylesheet. |
58 | | - // This helps ensure element styles are always in registration order. |
59 | | - if (needsStatic || !nativeShadow) { |
| 65 | + if (!this._needsStyleProperties() && this._styles.length) { |
60 | 66 | // NOTE: IE has css style ordering issues unless there's at least a |
61 | 67 | // space in the stylesheet. |
62 | | - cssText = needsStatic ? cssText : ' '; |
63 | 68 | var style = styleUtil.applyCss(cssText, this.is, |
64 | | - nativeShadow ? this._template.content : null); |
| 69 | + nativeShadow ? this._template.content : null, this._scopeStyle); |
65 | 70 | // keep track of style when in document scope (polyfill) so we can |
66 | 71 | // attach property styles after it. |
67 | 72 | if (!nativeShadow) { |
| 73 | + // remove old scope style (comment node) when it's not needed. |
| 74 | + if (this._scopeStyle) { |
| 75 | + this._scopeStyle.parentNode.removeChild(this._scopeStyle); |
| 76 | + } |
68 | 77 | this._scopeStyle = style; |
69 | 78 | } |
70 | 79 | } |
|
0 commit comments