Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit 0d285e7

Browse files
authored
Merge pull request #665 from webcomponents/revert-644-541-memory-leak-ie11
Revert "fixed memory leak while importing html elements in IE"
2 parents 0d6b57b + 708624f commit 0d285e7

9 files changed

Lines changed: 18 additions & 56 deletions

File tree

src/CustomElements/observe.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,7 @@ function takeRecords(node) {
251251
while (node.parentNode) {
252252
node = node.parentNode;
253253
}
254-
255-
// The node is a ShadowRoot, an IE will have a memory leak if you put the observer
256-
// directly on the ShadowRoot, so put it on the head so it does not leak
257-
var observer = node.head.__observer;
254+
var observer = node.__observer;
258255
if (observer) {
259256
handler(node, observer.takeRecords());
260257
takeMutations();
@@ -263,29 +260,19 @@ function takeRecords(node) {
263260

264261
var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);
265262

263+
266264
// observe a node tree; bail if it's already being observed.
267265
function observe(inRoot) {
268-
269-
if (inRoot && inRoot.head && inRoot.head.__observer) {
266+
if (inRoot.__observer) {
270267
return;
271268
}
272269
// For each ShadowRoot, we create a new MutationObserver, so the root can be
273270
// garbage collected once all references to the `inRoot` node are gone.
274271
// Give the handler access to the root so that an 'in document' check can
275272
// be done.
276-
277-
// originally the observer was on the ShadowRoot (inRoot) (single observer);
278-
// this causes a memory leak within IE. To fix this, we must put a an observer
279-
// on both the head and body nodes on the ShadowRoot
280273
var observer = new MutationObserver(handler.bind(this, inRoot));
281-
observer.observe(inRoot.head, {childList: true, subtree: true});
282-
observer.observe(inRoot.body, {childList: true, subtree: true});
283-
284-
// this needs to be on head or it will leak in IE
285-
// IE does not like it when you have non-standard attributes on root dom's, so put
286-
// the observer on the head element
287-
// this is used to check if the observer has been attached already (above)
288-
inRoot.head.__observer = observer;
274+
observer.observe(inRoot, {childList: true, subtree: true});
275+
inRoot.__observer = observer;
289276
}
290277

291278
// upgrade an entire document and observe it for elements changes.

src/HTMLImports/Observer.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ Observer.prototype = {
4040
},
4141

4242
observe: function(root) {
43-
// IE will leak if you put an observer on a root shadow document
44-
// so observe changes to both the head and body
45-
this.mo.observe(root.head, {childList: true, subtree: true});
46-
this.mo.observe(root.body, {childList: true, subtree: true});
43+
this.mo.observe(root, {childList: true, subtree: true});
4744
}
4845

4946
};

src/HTMLImports/importer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ var importer = {
7474
// generate an HTMLDocument from data
7575
doc = err ? null : makeDocument(resource, redirectedUrl || url);
7676
if (doc) {
77-
// IE will leak if you put the node directly on the ShadowRoot (doc)
78-
// instead appending to ShadowRoot head for reference
79-
doc.head.__importLink = elt;
77+
doc.__importLink = elt;
8078
// note, we cannot use MO to detect parsed nodes because
8179
// SD polyfill does not report these as mutations.
8280
this.bootDocument(doc);

src/HTMLImports/parser.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,8 @@ var importParser = {
161161

162162
rootImportForElement: function(elt) {
163163
var n = elt;
164-
// IE will leak if you put the import link directly on the ownerDocument (shadow root)
165-
// so the link is appended on the head element.
166-
while (n.ownerDocument.head.__importLink) {
167-
n = n.ownerDocument.head.__importLink;
164+
while (n.ownerDocument.__importLink) {
165+
n = n.ownerDocument.__importLink;
168166
}
169167
return n;
170168
},

src/ShadowDOM/wrappers/Element.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@
7676
var renderer = scope.getRendererForHost(this);
7777
renderer.invalidate();
7878

79-
// This is needed for IE - if you put elements directly on the root shadow
80-
// IE will leak, create head and body so we can append observers, etc.
81-
newShadowRoot.head = document.createElement('head');
82-
newShadowRoot.body = document.createElement('body');
83-
8479
return newShadowRoot;
8580
},
8681

tests/HTMLImports/html/dynamic-all-imports-detail.html

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,11 @@
4646

4747
test('HTMLImports whenready detail', function(done) {
4848
HTMLImports.whenReady(function(detail) {
49+
chai.assert.equal(detail.allImports.length, 2);
50+
chai.assert.equal(detail.loadedImports.length, 2);
4951

50-
var allImports = document.querySelectorAll('link[rel="import"]');
51-
52-
chai.assert.equal(detail.allImports.length, allImports.length);
53-
chai.assert.equal(detail.loadedImports.length, allImports.length);
54-
55-
var importsArray = Array.prototype.slice.call(detail.allImports);
56-
57-
chai.expect(importsArray.filter(function(el){ return el.href.indexOf('imports/load-1.html') >= 0;}));
58-
chai.expect(importsArray.filter(function(el){ return el.href.indexOf('imports/load-2.html') >= 0;}));
52+
chai.expect(detail.allImports[0].href).to.contain('imports/load-1.html');
53+
chai.expect(detail.allImports[1].href).to.contain('imports/load-2.html');
5954

6055
done()
6156
});

tests/HTMLImports/html/dynamic-errors-detail.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@
4646

4747
test('HTMLImports whenready errors', function(done) {
4848
HTMLImports.whenReady(function(detail) {
49-
var allImports = document.querySelectorAll('link[rel="import"]');
50-
chai.assert.equal(detail.allImports.length, allImports.length);
49+
chai.assert.equal(detail.allImports.length, 2);
5150
chai.assert.equal(detail.errorImports.length, 1);
52-
chai.assert.equal(detail.loadedImports.length, allImports.length - 1);
51+
chai.assert.equal(detail.loadedImports.length, 1);
5352

5453
var errorImport = detail.errorImports[0];
5554
chai.expect(errorImport.href).to.contain('imports/load-does-not-exist.html');

tests/HTMLImports/html/load-404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
function check() {
4242
clearTimeout(timeout);
43-
chai.assert.equal(document.querySelector('link[href="imports/404-1.html"]').import, null, '404\'d link.import is null');
43+
chai.assert.equal(document.querySelector('link').import, null, '404\'d link.import is null');
4444
chai.assert.equal(errors, 2, '404\'d generate error event');
4545
done();
4646
}

tests/WebComponents/html/smoke.html

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
<x-foo>plain</x-foo>
2121
<button is="x-baz">plain</button>
2222
<script>
23-
var isNativeShadowDomSupported;
2423
test('smoke', function(done) {
25-
isNativeShadowDomSupported = !!unwrap(document.createElement('div')).createShadowRoot;
2624
var p = Object.create(HTMLElement.prototype);
2725
p.createdCallback = function() {
2826
this.textContent = 'custom!';
@@ -59,13 +57,8 @@
5957
done();
6058
}
6159
var ob = new MutationObserver(handler);
62-
if( isNativeShadowDomSupported ) {
63-
ob.observe(root, {childList: true, subtree: true});
64-
root.appendChild(xzot);
65-
} else {
66-
ob.observe(root.body, {childList: true, subtree: true});
67-
root.body.appendChild(xzot);
68-
}
60+
ob.observe(root, {childList: true, subtree: true});
61+
root.appendChild(xzot);
6962
});
7063
</script>
7164
</body>

0 commit comments

Comments
 (0)