Skip to content

Commit

Permalink
Improvement to @windyGex's awesome work from #717. This entirely remo…
Browse files Browse the repository at this point in the history
…ves the cases where preact would erroneously invoke appendChild() when it didn't need to. The diff no longer depends on DOM length values 🎉 Big thanks to @e1ectronic for pointing this out and providing a great repro (http://jsfiddle.net/o402afwp/).
  • Loading branch information
developit committed Jun 3, 2017
1 parent 2ef872d commit 92f65df
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/vdom/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function innerDiffNode(dom, vchildren, context, mountAll, isHydrating) {
len = originalChildren.length,
childrenLen = 0,
vlen = vchildren ? vchildren.length : 0,
j, c, vchild, child;
j, c, f, vchild, child;

// Build up a map of keyed children and an Array of unkeyed children:
if (len!==0) {
Expand Down Expand Up @@ -218,17 +218,16 @@ function innerDiffNode(dom, vchildren, context, mountAll, isHydrating) {
// morph the matched/found/created DOM child to match vchild (deep)
child = idiff(child, vchild, context, mountAll);

if (child && child!==dom) {
if (i>len) {
f = originalChildren[i];
if (child && child!==dom && child!==f) {
if (f==null) {
dom.appendChild(child);
}
else if (child!==originalChildren[i]) {
if (child===originalChildren[i+1]) {
removeNode(originalChildren[i]);
}
else {
dom.insertBefore(child, originalChildren[i] || null);
}
else if (child===f.nextSibling) {
removeNode(f);
}
else {
dom.insertBefore(child, f);
}
}
}
Expand Down

0 comments on commit 92f65df

Please sign in to comment.