Skip to content

legacy-undefined-noBatch: Put adoptedStyleSheets use behind a global setting #5645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 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, 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';
Expand Down Expand Up @@ -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) {
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 shareBuiltCSSWithAdoptedStyleSheets =
window.Polymer && window.Polymer.shareBuiltCSSWithAdoptedStyleSheets || false;

/**
* Sets `shareBuiltCSSWithAdoptedStyleSheets` globally.
*
* @param {boolean} value enable or disable `shareBuiltCSSWithAdoptedStyleSheets`
* @return {void}
*/
export const setShareBuiltCSSWithAdoptedStyleSheets = function(value) {
shareBuiltCSSWithAdoptedStyleSheets = 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 {
setShareBuiltCSSWithAdoptedStyleSheets,
supportsAdoptingStyleSheets,
} from '../../lib/utils/settings.js';
setShareBuiltCSSWithAdoptedStyleSheets(true);
window.supportsAdoptingStyleSheets = supportsAdoptingStyleSheets;
let define = window.customElements.define;
let order = [];
Expand Down