From f9a8bdcafe2900902c9912eee8aeec2a0c1fb557 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Mon, 9 Nov 2015 15:22:23 -0800 Subject: [PATCH] Handle multiple DOM updates without interference This test failed before! How embarrassing. --- .../dom/client/utils/DOMChildrenOperations.js | 4 +-- .../__tests__/ReactDOMComponent-test.js | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/renderers/dom/client/utils/DOMChildrenOperations.js b/src/renderers/dom/client/utils/DOMChildrenOperations.js index 255e634688..02faac4dad 100644 --- a/src/renderers/dom/client/utils/DOMChildrenOperations.js +++ b/src/renderers/dom/client/utils/DOMChildrenOperations.js @@ -83,7 +83,7 @@ var DOMChildrenOperations = { update.type === ReactMultiChildUpdateTypes.REMOVE_NODE) { var updatedIndex = update.fromIndex; var updatedChild = update.parentNode.childNodes[updatedIndex]; - var parentID = update.parentID; + var parentID = update.parentInst._rootNodeID; invariant( updatedChild, @@ -143,7 +143,7 @@ var DOMChildrenOperations = { case ReactMultiChildUpdateTypes.MOVE_EXISTING: insertChildAt( update.parentNode, - initialChildren[update.parentID][update.fromIndex], + initialChildren[update.parentInst._rootNodeID][update.fromIndex], update.toIndex ); break; diff --git a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js index 9f6528c35b..f29f2f3c85 100644 --- a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js +++ b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js @@ -454,6 +454,40 @@ describe('ReactDOMComponent', function() { ReactDOM.render(
, container); expect(setter.mock.calls.length).toBe(1); }); + + it('handles multiple child updates without interference', function() { + // This test might look like it's just testing ReactMultiChild but the + // last bug in this was actually in DOMChildrenOperations so this test + // needs to be in some DOM-specific test file. + var container = document.createElement('div'); + + // ABCD + ReactDOM.render( +
+
+
A
B
+
+
+
C
D
+
+
, + container + ); + // BADC + ReactDOM.render( +
+
+
B
A
+
+
+
D
C
+
+
, + container + ); + + expect(container.textContent).toBe('BADC'); + }); }); describe('createOpenTagMarkup', function() {