Skip to content

Commit

Permalink
fix: drop support for ShadyCSS
Browse files Browse the repository at this point in the history
  • Loading branch information
Lodin committed Sep 2, 2019
1 parent 2895c86 commit 209fe3b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 52 deletions.
18 changes: 1 addition & 17 deletions src/ConstructStyleSheet.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
constructStyleSheetRegistry,
deferredStyleSheets,
frame, hasShadyCss, shadyCssAdoptersRegistry,
frame,
state,
} from './shared';
import {instanceOfStyleSheet} from './utils';
Expand Down Expand Up @@ -42,14 +42,6 @@ export function updatePrototype(proto) {
}
});

if (hasShadyCss && shadyCssAdoptersRegistry.has(this)) {
const location = shadyCssAdoptersRegistry.get(this);

// We need to call adoptedStyleSheets setter to re-assign styles
// to ShadyCSS.
location.adoptedStyleSheets = location.adoptedStyleSheets;
}

// And we also need to remember all these changes to apply them to
// each newly adopted style element.
actions.push([methodKey, args]);
Expand All @@ -66,14 +58,6 @@ function updateAdopters(sheet) {
adopters.forEach(styleElement => {
styleElement.innerHTML = basicStyleElement.innerHTML;
});

if (hasShadyCss && shadyCssAdoptersRegistry.has(sheet)) {
const location = shadyCssAdoptersRegistry.get(sheet);

// We need to call adoptedStyleSheets setter to re-assign styles
// to ShadyCSS.
location.adoptedStyleSheets = location.adoptedStyleSheets;
}
}

// This class will be a substitute for the CSSStyleSheet class that
Expand Down
31 changes: 2 additions & 29 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import {
adoptedStyleSheetsRegistry,
deferredStyleSheets,
frame,
hasShadyCss,
shadyCssAdoptersRegistry,
state,
} from './shared';
import {checkAndPrepare, reduce} from './utils';
import {checkAndPrepare} from './utils';

// Initialize the polyfill — Will be called on the window's load event
export function initPolyfill() {
Expand Down Expand Up @@ -84,32 +82,7 @@ export function initAdoptedStyleSheets() {
adoptedStyleSheetAccessors,
);

if (hasShadyCss) {
Object.defineProperty(ShadowRoot.prototype, 'adoptedStyleSheets', {
configurable: true,
get() {
return adoptedStyleSheetsRegistry.get(this) || [];
},
set(sheets) {
const uniqueSheets = checkAndPrepare(sheets, this);

const cssToAdopt = uniqueSheets.map(({cssRules}) =>
reduce.call(cssRules, (text, {cssText}) => `${text} ${cssText}`, ''),
);

ShadyCSS.ScopingShim.prepareAdoptedCssText(
cssToAdopt,
this.host.localName,
);

uniqueSheets.forEach(sheet =>
shadyCssAdoptersRegistry.set(sheet, this),
);

ShadyCSS.styleSubtree(this.host);
},
});
} else if (typeof ShadowRoot !== 'undefined') {
if (typeof ShadowRoot !== 'undefined') {
const oldAttachShadow = HTMLElement.prototype.attachShadow;

// Shadow root of each element should be observed to add styles to all
Expand Down
8 changes: 4 additions & 4 deletions src/shared.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const hasShadyCss = 'ShadyCSS' in window;
// Even if the polyfill does not support ShadyCSS, it should be detected in
// order to avoid errors of parallel usage.
export const hasShadyCss =
'ShadyCSS' in window && !window.ShadyCSS.nativeShadow;

// Style elements that will be attached to the head
// that need to be moved to the iframe
Expand All @@ -21,9 +24,6 @@ export const observerRegistry = new WeakMap();
// for the specific style element.
export const appliedActionsCursorRegistry = new WeakMap();

// The list of ShadowRoots for specific sheet (when ShadyCSS is enabled).
export const shadyCssAdoptersRegistry = new WeakMap();

export const state = {
// Can we rely on document.body
loaded: false,
Expand Down
2 changes: 0 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ export function checkAndPrepare(sheets, location) {

return uniqueSheets;
}

export const {reduce} = Array.prototype;

0 comments on commit 209fe3b

Please sign in to comment.