diff --git a/src/diff/children.js b/src/diff/children.js index e55fc97017f..b759a34f556 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -205,17 +205,6 @@ export function diffChildren( // Remove remaining oldChildren if there are any. for (i = oldChildrenLength; i--; ) { if (oldChildren[i] != null) { - if ( - typeof newParentVNode.type == 'function' && - oldChildren[i]._dom != null && - oldChildren[i]._dom == newParentVNode._nextDom - ) { - // If the newParentVNode.__nextDom points to a dom node that is about to - // be unmounted, then get the next sibling of that vnode and set - // _nextDom to it - newParentVNode._nextDom = getDomSibling(oldParentVNode, i + 1); - } - unmount(oldChildren[i], oldChildren[i]); } } diff --git a/test/browser/fragments.test.js b/test/browser/fragments.test.js index 882aeed9550..a5d92c7998a 100644 --- a/test/browser/fragments.test.js +++ b/test/browser/fragments.test.js @@ -237,7 +237,9 @@ describe('Fragment', () => { expectDomLogToBe([ '
.appendChild(#text)', '
122.insertBefore(
1, 1)', - '1.remove()' + '1.remove()', + '
122.appendChild(2)', + '
122.appendChild(2)' ]); }); @@ -2658,7 +2660,7 @@ describe('Fragment', () => { render(, scratch); expect(scratch.innerHTML).to.equal(div([div(1), div('A')])); - expectDomLogToBe(['
2.remove()']); + expectDomLogToBe(['
2.remove()', '
1A.appendChild(
A)']); }); it('should efficiently unmount nested Fragment children', () => { @@ -2702,7 +2704,12 @@ describe('Fragment', () => { render(, scratch); expect(scratch.innerHTML).to.equal(div([div(1), div('A'), div('B')])); - expectDomLogToBe(['
2.remove()', '
3.remove()']); + expectDomLogToBe([ + '
2.remove()', + '
3.remove()', + '
1AB.appendChild(
A)', + '
1BA.appendChild(
B)' + ]); }); it('should efficiently place new children and unmount nested Fragment children', () => { @@ -2751,7 +2758,9 @@ describe('Fragment', () => { '
.appendChild(#text)', '
123AB.insertBefore(
4,
2)', '
2.remove()', - '
3.remove()' + '
3.remove()', + '
14AB.appendChild(
A)', + '
14BA.appendChild(
B)' ]); }); @@ -2799,7 +2808,66 @@ describe('Fragment', () => { '
123AB.insertBefore(1,
1)', '
2.remove()', '
3.remove()', - '
1.remove()' + '
1.remove()', + '
1AB.appendChild(
A)', + '
1BA.appendChild(
B)' ]); }); + + it('should swap nested fragments correctly', () => { + let swap; + class App extends Component { + constructor(props) { + super(props); + this.state = { first: true }; + } + + render() { + if (this.state.first) { + return ( + + { + +

1. Original item first paragraph

+
+ } +

2. Original item second paragraph

+ +
+ ); + } + return ( + +

1. Second item first paragraph

+ +

2. Second item second paragraph

+
+ + + + ); + } + } + + render(, scratch); + expect(scratch.innerHTML).to.equal( + '

1. Original item first paragraph

2. Original item second paragraph

' + ); + + swap(); + rerender(); + expect(scratch.innerHTML).to.equal( + '

1. Second item first paragraph

2. Second item second paragraph

' + ); + + swap(); + rerender(); + expect(scratch.innerHTML).to.equal( + '

1. Original item first paragraph

2. Original item second paragraph

' + ); + }); });