updated comments to make clearer what is going on with the memory leaks in IE

This commit is contained in:
Steve To
2016-11-15 13:01:25 -05:00
parent 547cddf4a3
commit e2d563ae5d
2 changed files with 7 additions and 8 deletions

View File

@@ -252,9 +252,8 @@ function takeRecords(node) {
node = node.parentNode;
}
// this needs to be on head or it will leak in IE
// IE does not like it when you have non-standard attributes on root dom's, so put
// the observer on the head element
// The node is a ShadowRoot, an IE will have a memory leak if you put the observer
// directly on the ShadowRoot, so put it on the head so it does not leak
var observer = node.head.__observer;
if (observer) {
handler(node, observer.takeRecords());
@@ -264,7 +263,6 @@ function takeRecords(node) {
var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);
// observe a node tree; bail if it's already being observed.
function observe(inRoot) {
@@ -276,8 +274,9 @@ function observe(inRoot) {
// Give the handler access to the root so that an 'in document' check can
// be done.
// IE requires that you put an observer on child elements of the DOM or it will leak
// at this point inRoot == #document
// originally the observer was on the ShadowRoot (inRoot) (single observer);
// this causes a memory leak within IE. To fix this, we must put a an observer
// on both the head and body nodes on the ShadowRoot
var observer = new MutationObserver(handler.bind(this, inRoot));
observer.observe(inRoot.head, {childList: true, subtree: true});
observer.observe(inRoot.body, {childList: true, subtree: true});

View File

@@ -74,8 +74,8 @@ var importer = {
// generate an HTMLDocument from data
doc = err ? null : makeDocument(resource, redirectedUrl || url);
if (doc) {
// IE will leak if you put the node directly on the shadow dom
// instead appending to head for reference
// IE will leak if you put the node directly on the ShadowRoot (doc)
// instead appending to ShadowRoot head for reference
doc.head.__importLink = elt;
// note, we cannot use MO to detect parsed nodes because
// SD polyfill does not report these as mutations.