Skip to content

Commit c73f952

Browse files
committed
Merge pull request #4408 from jimfb/remove-children-map
Removed flattened children object. Fixes #4405
2 parents 2ea0bd7 + fe99e59 commit c73f952

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/renderers/shared/reconciler/ReactChildReconciler.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,32 @@ var ReactReconciler = require('ReactReconciler');
1717
var flattenChildren = require('flattenChildren');
1818
var instantiateReactComponent = require('instantiateReactComponent');
1919
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
20+
var traverseAllChildren = require('traverseAllChildren');
21+
var warning = require('warning');
22+
23+
function instantiateChild(childInstances, child, name) {
24+
// We found a component instance.
25+
var keyUnique = (childInstances[name] === undefined);
26+
if (__DEV__) {
27+
warning(
28+
keyUnique,
29+
'flattenChildren(...): Encountered two children with the same key, ' +
30+
'`%s`. Child keys must be unique; when two children share a key, only ' +
31+
'the first child will be used.',
32+
name
33+
);
34+
}
35+
if (child != null && keyUnique) {
36+
childInstances[name] = instantiateReactComponent(child, null);
37+
}
38+
}
2039

2140
/**
2241
* ReactChildReconciler provides helpers for initializing or updating a set of
2342
* children. Its output is suitable for passing it onto ReactMultiChild which
2443
* does diffed reordering and insertion.
2544
*/
2645
var ReactChildReconciler = {
27-
2846
/**
2947
* Generates a "mount image" for each of the supplied children. In the case
3048
* of `ReactDOMComponent`, a mount image is a string of markup.
@@ -34,17 +52,12 @@ var ReactChildReconciler = {
3452
* @internal
3553
*/
3654
instantiateChildren: function(nestedChildNodes, transaction, context) {
37-
var children = flattenChildren(nestedChildNodes);
38-
for (var name in children) {
39-
if (children.hasOwnProperty(name)) {
40-
var child = children[name];
41-
// The rendered children must be turned into instances as they're
42-
// mounted.
43-
var childInstance = instantiateReactComponent(child, null);
44-
children[name] = childInstance;
45-
}
55+
if (nestedChildNodes == null) {
56+
return null;
4657
}
47-
return children;
58+
var childInstances = {};
59+
traverseAllChildren(nestedChildNodes, instantiateChild, childInstances);
60+
return childInstances;
4861
},
4962

5063
/**

0 commit comments

Comments
 (0)