Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 9fb2203

Browse files
committed
appendChild from a tree with a rendered causes failures
The following fails to correctly update the internal pointers. treeWithoutRenderer.appendChild(childFromParentWithRenderer) Fixes #438
1 parent e25f9a7 commit 9fb2203

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/wrappers/Node.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,11 @@
401401
} else {
402402
if (!previousNode)
403403
this.firstChild_ = nodes[0];
404-
if (!refWrapper)
404+
if (!refWrapper) {
405405
this.lastChild_ = nodes[nodes.length - 1];
406+
if (this.firstChild_ === undefined)
407+
this.firstChild_ = this.firstChild;
408+
}
406409

407410
var parentNode = refNode ? refNode.parentNode : this.impl;
408411

test/js/Node.js

+21
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,25 @@ suite('Node', function() {
392392
assert.equal(sr.firstChild.nextSibling.textContent, 'quux');
393393
});
394394

395+
test('appendChild last and first', function() {
396+
var a = document.createElement('a');
397+
a.innerHTML = '<b></b>';
398+
var b = a.firstChild;
399+
var sr = a.createShadowRoot();
400+
401+
var c = document.createElement('c');
402+
c.innerHTML = '<d></d>';
403+
var d = c.firstChild;
404+
c.appendChild(b);
405+
406+
var cs = c.childNodes;
407+
assert.equal(cs.length, 2);
408+
assert.equal(cs[0], d);
409+
assert.equal(cs[1], b);
410+
411+
c.removeChild(b);
412+
cs = c.childNodes;
413+
assert.equal(cs.length, 1);
414+
assert.equal(cs[0], d);
415+
});
395416
});

0 commit comments

Comments
 (0)