From 2fc9062d83aa34246bbc3809a586441c2d1c1c76 Mon Sep 17 00:00:00 2001 From: Russell Bicknell Date: Thu, 2 Apr 2020 17:17:10 -0700 Subject: [PATCH 1/5] Add `shareBuiltCSSWithAdoptedStyleSheets` global setting --- lib/utils/settings.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/utils/settings.js b/lib/utils/settings.js index f67f55fe97..7b858c2284 100644 --- a/lib/utils/settings.js +++ b/lib/utils/settings.js @@ -338,4 +338,22 @@ export let legacyNoObservedAttributes = */ export const setLegacyNoObservedAttributes = function(noObservedAttributes) { legacyNoObservedAttributes = noObservedAttributes; -}; \ No newline at end of file +}; + +/** + * Setting to enable use of `adoptedStyleSheets` for sharing style sheets + * between component instances' shadow roots, if the app uses built Shady CSS + * styles. + */ +export let shareBuiltCSSWithAdoptedStyleSheets = + window.Polymer && window.Polymer.shareBuiltCSSWithAdoptedStyleSheets || false; + +/** + * Sets `shareBuiltCSSWithAdoptedStyleSheets` globally. + * + * @param {boolean} newValue enable or disable `shareBuiltCSSWithAdoptedStyleSheets` + * @return {void} + */ +export const setShareBuiltCSSWithAdoptedStyleSheets = function(value) { + shareBuiltCSSWithAdoptedStyleSheets = value; +}; From bdd765810a59c352ddba1950dc9f336021368dc5 Mon Sep 17 00:00:00 2001 From: Russell Bicknell Date: Thu, 2 Apr 2020 17:23:57 -0700 Subject: [PATCH 2/5] Gate feature behind `shareBuiltCSSWithAdoptedStyleSheets`; update tests. --- lib/mixins/element-mixin.js | 4 ++-- test/unit/styling-build-adopted-stylesheets.html | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/mixins/element-mixin.js b/lib/mixins/element-mixin.js index b31e25f8b4..8cd3691416 100644 --- a/lib/mixins/element-mixin.js +++ b/lib/mixins/element-mixin.js @@ -11,7 +11,7 @@ */ import '../utils/boot.js'; -import { rootPath, strictTemplatePolicy, allowTemplateFromDomModule, legacyOptimizations, legacyWarnings, syncInitialRender, supportsAdoptingStyleSheets} from '../utils/settings.js'; +import { rootPath, strictTemplatePolicy, allowTemplateFromDomModule, legacyOptimizations, legacyWarnings, syncInitialRender, supportsAdoptingStyleSheets, shareBuiltCSSWithAdoptedStyleSheets } from '../utils/settings.js'; import { dedupingMixin } from '../utils/mixin.js'; import { stylesFromTemplate, stylesFromModuleImports } from '../utils/style-gather.js'; import { pathFromUrl, resolveCss, resolveUrl } from '../utils/resolve-url.js'; @@ -304,7 +304,7 @@ export const ElementMixin = dedupingMixin(base => { // potentially not shareable and sharing the ones that could be shared // would require some coordination. To keep it simple, all the includes // and styles are collapsed into a single shareable stylesheet. - if (builtCSS && supportsAdoptingStyleSheets) { + if (shareBuiltCSSWithAdoptedStyleSheets && builtCSS && supportsAdoptingStyleSheets) { // Remove styles in template and make a shareable stylesheet const styles = template.content.querySelectorAll('style'); if (styles) { diff --git a/test/unit/styling-build-adopted-stylesheets.html b/test/unit/styling-build-adopted-stylesheets.html index b917cfe505..3e511d9447 100644 --- a/test/unit/styling-build-adopted-stylesheets.html +++ b/test/unit/styling-build-adopted-stylesheets.html @@ -18,7 +18,11 @@