Don't use existing "root" ID if non-root
Before, if you had ``` container = <div data-reactid=".0"><div data-reactid=".0.0" /></div>; ``` and did `ReactDOM.render(<span />, container)` you would get ``` <div data-reactid=".0"><span data-reactid=".0" /></div>; ``` (along with a warning not to replace React-rendered children with a new tree like that). But that makes no sense -- the span should have a new index, not truncate the ID of the old child it's replacing. (Now tests pass again with useCreateElement on; before they threw a "valid but unequal" on our test for this warning.)
Ben Alpert committed
Sep 26, 2015 at 14:15 UTC
e4a43389b84aa9b9278f432de64bbd5174e076ef
1 file changed
+6
-9
src/renderers/dom/client/ReactMount.js
+6
-9
@@ -724,19 +724,16 @@ var ReactMount = {
724
* @return {string} The "reactRoot" ID of elements rendered within.
725
*/
726
registerContainer: function(container) {
727
- var reactRootID = getReactRootID(container);
728
- if (reactRootID) {
729
- // If one exists, make sure it is a valid "reactRoot" ID.
730
- reactRootID = ReactInstanceHandles.getReactRootIDFromNodeID(reactRootID);
731
- }
732
- if (!reactRootID) {
727
+ var id = getReactRootID(container);
728
+ // If one exists, make sure it is a valid "reactRoot" ID.
729
+ if (!id || id !== ReactInstanceHandles.getReactRootIDFromNodeID(id)) {
730
// No valid "reactRoot" ID found, create one.
734
- reactRootID = ReactInstanceHandles.createReactRootID(
731
+ id = ReactInstanceHandles.createReactRootID(
732
ClientReactRootIndex.createReactRootIndex()
733
);
734
}
738
- containersByReactRootID[reactRootID] = container;
739
- return reactRootID;
735
+ containersByReactRootID[id] = container;
736
+ return id;
737
},
738
739
/**