diff --git a/src/diff/children.js b/src/diff/children.js index 912cc72d7c..fb31e7b15c 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -302,20 +302,26 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) { childVNode._flags |= INSERT_VNODE; } } else if (matchingIndex !== skewedIndex) { - if (matchingIndex === skewedIndex + 1) { + if (matchingIndex == skewedIndex - 1) { + skew = matchingIndex - skewedIndex; + } else if (matchingIndex == skewedIndex + 1) { skew++; } else if (matchingIndex > skewedIndex) { + // Our matched DOM-node is further in the list of children than + // where it's at now. + + // When the remaining old children is bigger than the new-children + // minus our skewed index we know we are dealing with a shrinking list + // we have to increase our skew with the matchedIndex - the skewed index if (remainingOldChildren > newChildrenLength - skewedIndex) { skew += matchingIndex - skewedIndex; } else { + // If we have matched all the children just decrease the skew skew--; } } else if (matchingIndex < skewedIndex) { - if (matchingIndex == skewedIndex - 1) { - skew = matchingIndex - skewedIndex; - } - } else { - skew = 0; + // When our new position is in front of our old position than we increase the skew + skew++; } // Move this VNode's DOM if the original index (matchingIndex) doesn't diff --git a/test/browser/render.test.js b/test/browser/render.test.js index f440962f70..4755607c12 100644 --- a/test/browser/render.test.js +++ b/test/browser/render.test.js @@ -474,17 +474,17 @@ describe('render()', () => { it('should support popover auto', () => { render(
, scratch); - expect(scratch.innerHTML).to.equal(""); + expect(scratch.innerHTML).to.equal(''); }); it('should support popover true boolean', () => { render(, scratch); - expect(scratch.innerHTML).to.equal(""); + expect(scratch.innerHTML).to.equal(''); }); it('should support popover false boolean', () => { render(, scratch); - expect(scratch.innerHTML).to.equal(""); + expect(scratch.innerHTML).to.equal(''); }); // Test for preactjs/preact#4340 @@ -1625,4 +1625,68 @@ describe('render()', () => { '