Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/legacy-undefined-noBatch' into l…
Browse files Browse the repository at this point in the history
…egacy-undefined-noBatch_release-notes
  • Loading branch information
bicknellr committed Apr 7, 2020
2 parents 9c78b48 + 742a103 commit fe696f1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/mixins/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, useAdoptedStyleSheetsWithBuiltCSS } 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';
Expand Down Expand Up @@ -304,7 +304,8 @@ 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 (useAdoptedStyleSheetsWithBuiltCSS && builtCSS &&
supportsAdoptingStyleSheets) {
// Remove styles in template and make a shareable stylesheet
const styles = template.content.querySelectorAll('style');
if (styles) {
Expand Down
20 changes: 19 additions & 1 deletion lib/utils/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,22 @@ export let legacyNoObservedAttributes =
*/
export const setLegacyNoObservedAttributes = function(noObservedAttributes) {
legacyNoObservedAttributes = noObservedAttributes;
};
};

/**
* 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 useAdoptedStyleSheetsWithBuiltCSS =
window.Polymer && window.Polymer.useAdoptedStyleSheetsWithBuiltCSS || false;

/**
* Sets `useAdoptedStyleSheetsWithBuiltCSS` globally.
*
* @param {boolean} value enable or disable `useAdoptedStyleSheetsWithBuiltCSS`
* @return {void}
*/
export const setUseAdoptedStyleSheetsWithBuiltCSS = function(value) {
useAdoptedStyleSheetsWithBuiltCSS = value;
};
6 changes: 5 additions & 1 deletion test/unit/styling-build-adopted-stylesheets.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
<script src="wct-browser-config.js"></script>
<script src="../../node_modules/wct-browser-legacy/browser.js"></script>
<script type="module">
import { supportsAdoptingStyleSheets } from '../../lib/utils/settings.js';
import {
setUseAdoptedStyleSheetsWithBuiltCSS,
supportsAdoptingStyleSheets,
} from '../../lib/utils/settings.js';
setUseAdoptedStyleSheetsWithBuiltCSS(true);
window.supportsAdoptingStyleSheets = supportsAdoptingStyleSheets;
let define = window.customElements.define;
let order = [];
Expand Down

0 comments on commit fe696f1

Please sign in to comment.