Skip to content

Commit

Permalink
feat(polyfill): Shadow DOM nodes created before being connected now w…
Browse files Browse the repository at this point in the history
…ire themselves up when connected.
  • Loading branch information
calebdwilliams committed Jan 21, 2019
1 parent 68c76dd commit 33191f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions adoptedStyleSheets.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
(function() {
'use strict';
console.clear();

const supportsAdoptedStyleSheets = 'adoptedStyleSheets' in document;

if (!supportsAdoptedStyleSheets) {
const node = Symbol('constructible style sheets');
const constructed = Symbol('constructed');
const removalListener = Symbol('listener');
const iframe = document.createElement('iframe');
const mutationCallback = mutations => {
mutations.forEach(mutation => {
const { removedNodes } = mutation;
const { addedNodes, removedNodes } = mutation;
removedNodes.forEach(removed => {
if (removed[constructed]) {
setTimeout(() => {
removed[constructed].appendChild(removed);
});
}
});

addedNodes.forEach(added => {
const { shadowRoot } = added;
if (shadowRoot && shadowRoot.adoptedStyleSheets) {
shadowRoot.adoptedStyleSheets.forEach(adopted => {
shadowRoot.appendChild(adopted[node]._sheet);
});
}
})
});
};
const observer = new MutationObserver(mutationCallback);
Expand Down
2 changes: 1 addition & 1 deletion adoptedStyleSheets.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 33191f9

Please sign in to comment.