Skip to content

Commit

Permalink
Refine fix for #3461 so that the decision to apply a static or proper…
Browse files Browse the repository at this point in the history
…ty stylesheet relies on the same info.
  • Loading branch information
Steven Orvell committed Mar 1, 2016
1 parent e26a806 commit ff96f9e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
4 changes: 1 addition & 3 deletions polymer.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
this._prepConstructor();
// template
this._prepTemplate();
// styles
// styles and style properties
this._prepStyles();
// style properties
this._prepStyleProperties();
// template markup
this._prepAnnotations();
// accessors
Expand Down
9 changes: 7 additions & 2 deletions src/standard/styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@
// calculate shimmed styles (we must always do this as it
// stores shimmed style data in the css rules for later use)
var cssText = styleTransformer.elementStyles(this);
// do we really need to output shimmed styles
var needsStatic = this._needsStaticStyles(this._styles);
// prepare to shim style properties.
this._prepStyleProperties();
// do we really need to output static shimmed styles?
// only if no custom properties are used since otherwise
// styles are applied via property shimming.
var needsStatic = this._styles.length &&
!this._needsStyleProperties();
// under shady dom we always output a shimmed style (which may be
// empty) so that other dynamic stylesheets can always be placed
// after the element's main stylesheet.
Expand Down
19 changes: 1 addition & 18 deletions src/standard/x-styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,10 @@

Polymer.Base._addFeature({

// Skip applying CSS if there are some mixins or variables used
// since styles with mixins and variables will be added on later stages anyway,
// and will include styles applied here, no need to do this twice
_needsStaticStyles: function(styles) {
var needsStatic;
for (var i=0, l=styles.length, css; i < l; i++) {
css = styleUtil.parser._clean(styles[i].textContent);
css = propertyUtils.collectConsumingCssText(css);
needsStatic = needsStatic || Boolean(css);
if (css.match(propertyUtils.rx.MIXIN_MATCH) ||
css.match(propertyUtils.rx.VAR_MATCH)) {
return false;
}
}
return needsStatic;
},

_prepStyleProperties: function() {
// note: an element should produce an x-scope stylesheet
// if it has any _stylePropertyNames
this._ownStylePropertyNames = this._styles ?
this._ownStylePropertyNames = this._styles && this._styles.length ?
propertyUtils.decorateStyles(this._styles) :
null;
},
Expand Down
11 changes: 11 additions & 0 deletions test/unit/styling-cross-scope-apply.html
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,17 @@
assertComputed(d, '10px');
});

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

// TODO(sorvell): fix for #1761 was reverted; include test once this issue is addressed
test('mixin values can be overridden by subsequent concrete properties', function() {
assertComputed(styled.$.override, '19px');
Expand Down
11 changes: 11 additions & 0 deletions test/unit/styling-cross-scope-var.html
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,17 @@
assertComputed(d, '10px');
});

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

});

</script>
Expand Down

0 comments on commit ff96f9e

Please sign in to comment.