Skip to content

Commit ff96f9e

Browse files
author
Steven Orvell
committed
Refine fix for #3461 so that the decision to apply a static or property stylesheet relies on the same info.
1 parent e26a806 commit ff96f9e

5 files changed

Lines changed: 31 additions & 23 deletions

File tree

‎polymer.html‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@
3232
this._prepConstructor();
3333
// template
3434
this._prepTemplate();
35-
// styles
35+
// styles and style properties
3636
this._prepStyles();
37-
// style properties
38-
this._prepStyleProperties();
3937
// template markup
4038
this._prepAnnotations();
4139
// accessors

‎src/standard/styling.html‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@
4545
// calculate shimmed styles (we must always do this as it
4646
// stores shimmed style data in the css rules for later use)
4747
var cssText = styleTransformer.elementStyles(this);
48-
// do we really need to output shimmed styles
49-
var needsStatic = this._needsStaticStyles(this._styles);
48+
// prepare to shim style properties.
49+
this._prepStyleProperties();
50+
// do we really need to output static shimmed styles?
51+
// only if no custom properties are used since otherwise
52+
// styles are applied via property shimming.
53+
var needsStatic = this._styles.length &&
54+
!this._needsStyleProperties();
5055
// under shady dom we always output a shimmed style (which may be
5156
// empty) so that other dynamic stylesheets can always be placed
5257
// after the element's main stylesheet.

‎src/standard/x-styling.html‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,10 @@
2626

2727
Polymer.Base._addFeature({
2828

29-
// Skip applying CSS if there are some mixins or variables used
30-
// since styles with mixins and variables will be added on later stages anyway,
31-
// and will include styles applied here, no need to do this twice
32-
_needsStaticStyles: function(styles) {
33-
var needsStatic;
34-
for (var i=0, l=styles.length, css; i < l; i++) {
35-
css = styleUtil.parser._clean(styles[i].textContent);
36-
css = propertyUtils.collectConsumingCssText(css);
37-
needsStatic = needsStatic || Boolean(css);
38-
if (css.match(propertyUtils.rx.MIXIN_MATCH) ||
39-
css.match(propertyUtils.rx.VAR_MATCH)) {
40-
return false;
41-
}
42-
}
43-
return needsStatic;
44-
},
45-
4629
_prepStyleProperties: function() {
4730
// note: an element should produce an x-scope stylesheet
4831
// if it has any _stylePropertyNames
49-
this._ownStylePropertyNames = this._styles ?
32+
this._ownStylePropertyNames = this._styles && this._styles.length ?
5033
propertyUtils.decorateStyles(this._styles) :
5134
null;
5235
},

‎test/unit/styling-cross-scope-apply.html‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,17 @@
389389
assertComputed(d, '10px');
390390
});
391391

392+
test('producing a var that consumes results in static and not dynamic stylesheet', function() {
393+
var d = document.createElement('x-var-produce-via-consume');
394+
document.body.appendChild(d);
395+
CustomElements.takeRecords();
396+
var styleRoot = d.shadowRoot ? d.shadowRoot : document.head;
397+
var staticStyle = styleRoot.querySelector('style[scope=x-var-produce-via-consume]');
398+
assert.ok(staticStyle);
399+
assert.match(staticStyle.textContent, /display/, 'static style does not contain style content');
400+
assert.equal(styleRoot.querySelectorAll('style[scope~=x-var-produce-via-consume]').length, 1);
401+
});
402+
392403
// TODO(sorvell): fix for #1761 was reverted; include test once this issue is addressed
393404
test('mixin values can be overridden by subsequent concrete properties', function() {
394405
assertComputed(styled.$.override, '19px');

‎test/unit/styling-cross-scope-var.html‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,17 @@
890890
assertComputed(d, '10px');
891891
});
892892

893+
test('producing a var that consumes results in static and not dynamic stylesheet', function() {
894+
var d = document.createElement('x-var-produce-via-consume');
895+
document.body.appendChild(d);
896+
CustomElements.takeRecords();
897+
var styleRoot = d.shadowRoot ? d.shadowRoot : document.head;
898+
var staticStyle = styleRoot.querySelector('style[scope=x-var-produce-via-consume]');
899+
assert.ok(staticStyle);
900+
assert.match(staticStyle.textContent, /display/, 'static style does not contain style content');
901+
assert.equal(styleRoot.querySelectorAll('style[scope~=x-var-produce-via-consume]').length, 1);
902+
});
903+
893904
});
894905

895906
</script>

0 commit comments

Comments
 (0)