From 6d9048003ad7bc2e9aeb44efbe89ffa681bb20aa Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Wed, 22 Jun 2016 18:39:51 -0700 Subject: [PATCH] Ensure element scope selectors are updated correctly when updateStyles is called when element is not in dom. --- src/standard/x-styling.html | 6 ++++-- test/unit/styling-cross-scope-var.html | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/standard/x-styling.html b/src/standard/x-styling.html index 7fec48c9dc..934f31f2af 100644 --- a/src/standard/x-styling.html +++ b/src/standard/x-styling.html @@ -77,7 +77,9 @@ _beforeAttached: function() { // note: do this once automatically, // then requires calling `updateStyles` - if (!this._scopeSelector && this._needsStyleProperties()) { + if ((!this._scopeSelector || this.__stylePropertiesInvalid) && + this._needsStyleProperties()) { + this.__stylePropertiesInvalid = false; this._updateStyleProperties(); } }, @@ -274,7 +276,7 @@ // if called when an element is not attached, invalidate // styling by unsetting scopeSelector. } else { - this._scopeSelector = null; + this.__stylePropertiesInvalid = true; } if (this._styleCache) { this._styleCache.clear(); diff --git a/test/unit/styling-cross-scope-var.html b/test/unit/styling-cross-scope-var.html index f2a2c1511a..bd658cea19 100644 --- a/test/unit/styling-cross-scope-var.html +++ b/test/unit/styling-cross-scope-var.html @@ -979,11 +979,17 @@ assertComputed(x.$.child, '6px'); x.active = false; assertComputed(x.$.child, '0px'); + var scopeSelector = x.$.child._scopeSelector; document.body.removeChild(x); CustomElements.takeRecords(); x.active = true; document.body.appendChild(x); CustomElements.takeRecords(); + if (styled.shadyRoot && !Polymer.Settings.useNativeCSSProperties) { + assert.notEqual(scopeSelector, x.$.child._scopeSelector); + assert.isTrue(x.$.child.classList.contains(x.$.child._scopeSelector)); + assert.isFalse(x.$.child.classList.contains(scopeSelector)); + } assertComputed(x.$.child, '6px'); });