Skip to content

Commit

Permalink
fix(polyfill): Removed the iframe after collecting contentWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Williams committed Apr 3, 2019
1 parent e0cc8f8 commit 09b7d7f
Show file tree
Hide file tree
Showing 4 changed files with 1,872 additions and 289 deletions.
14 changes: 6 additions & 8 deletions adoptedStyleSheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
const node = Symbol('constructible style sheets');
const constructed = Symbol('constructed');
const obsolete = Symbol('obsolete');
const removalListener = Symbol('listener');
const iframe = document.createElement('iframe');
const mutationCallback = mutations => {
mutations.forEach(mutation => {
Expand All @@ -57,17 +56,16 @@
});
}
});


});
};

const observer = new MutationObserver(mutationCallback);
observer.observe(document.body, { childList: true });
iframe.hidden = true;
iframe.height = 0;
iframe.width = 0;
document.body.appendChild(iframe);

const frameBody = iframe.contentWindow.document.body;
document.body.removeChild(iframe);

const appendContent = (location, sheet) => {
const clone = sheet[node]._sheet.cloneNode(true);
location.body ? location = location.body : null;
Expand All @@ -87,7 +85,7 @@
constructor() {
this._adopters = [];
const style = document.createElement('style');
iframe.contentWindow.document.body.appendChild(style);
frameBody.appendChild(style);
this._sheet = style;
style.sheet[node] = this;
if (!style.sheet.constructor.prototype.replace) {
Expand Down Expand Up @@ -140,6 +138,6 @@
};

Object.defineProperty(ShadowRoot.prototype, 'adoptedStyleSheets', adoptedStyleSheetsConfig);
Object.defineProperty(document, 'adoptedStyleSheets', adoptedStyleSheetsConfig);
Object.defineProperty(Document.prototype, 'adoptedStyleSheets', adoptedStyleSheetsConfig);
}
}(undefined));
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.

Loading

0 comments on commit 09b7d7f

Please sign in to comment.