Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 012ab1f

Browse files
committed
fix(jqLite): correctly dealoc svg elements in IE
SVG elements in IE don't have a `.children` but only `.childNodes` so it broke. We started using `.children` for perf in e35abc9. This also acts as a perf improvements, since `getElementsByTagName` is faster than traversing the tree. Related #8075
1 parent 9c5b407 commit 012ab1f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/jqLite.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,16 @@ function jqLiteClone(element) {
243243
return element.cloneNode(true);
244244
}
245245

246-
function jqLiteDealoc(element){
247-
jqLiteRemoveData(element);
248-
var childElement;
249-
for ( var i = 0, children = element.children, l = (children && children.length) || 0; i < l; i++) {
250-
childElement = children[i];
251-
jqLiteDealoc(childElement);
246+
function jqLiteDealoc(element, onlyDescendants){
247+
if (!onlyDescendants) jqLiteRemoveData(element);
248+
249+
if (element.childNodes && element.childNodes.length) {
250+
// we use querySelectorAll because documentFragments don't have getElementsByTagName
251+
var descendants = element.getElementsByTagName ? element.getElementsByTagName('*') :
252+
element.querySelectorAll ? element.querySelectorAll('*') : [];
253+
for (var i = 0, l = descendants.length; i < l; i++) {
254+
jqLiteRemoveData(descendants[i]);
255+
}
252256
}
253257
}
254258

@@ -430,9 +434,7 @@ function jqLiteInheritedData(element, name, value) {
430434
}
431435

432436
function jqLiteEmpty(element) {
433-
for (var i = 0, childNodes = element.childNodes; i < childNodes.length; i++) {
434-
jqLiteDealoc(childNodes[i]);
435-
}
437+
jqLiteDealoc(element, true);
436438
while (element.firstChild) {
437439
element.removeChild(element.firstChild);
438440
}
@@ -630,9 +632,7 @@ forEach({
630632
if (isUndefined(value)) {
631633
return element.innerHTML;
632634
}
633-
for (var i = 0, childNodes = element.childNodes; i < childNodes.length; i++) {
634-
jqLiteDealoc(childNodes[i]);
635-
}
635+
jqLiteDealoc(element, true);
636636
element.innerHTML = value;
637637
},
638638

0 commit comments

Comments
 (0)