Removed flattened children object for initial render. Fixes #4405
Jim committed
Jul 16, 2015 at 16:23 UTC
fe99e59c8115f9b7e38d14e2020df176af995c21
1 file changed
+24
-11
src/renderers/shared/reconciler/ReactChildReconciler.js
+24
-11
@@ -17,6 +17,25 @@ var ReactReconciler = require('ReactReconciler');
17
var flattenChildren = require('flattenChildren');
18
var instantiateReactComponent = require('instantiateReactComponent');
19
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
+}
39
40
/**
41
* ReactChildReconciler provides helpers for initializing or updating a set of
@@ -24,7 +43,6 @@ var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
43
* does diffed reordering and insertion.
44
*/
45
var ReactChildReconciler = {
27
-
46
/**
47
* Generates a "mount image" for each of the supplied children. In the case
48
* of `ReactDOMComponent`, a mount image is a string of markup.
@@ -34,17 +52,12 @@ var ReactChildReconciler = {
52
* @internal
53
*/
54
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;
57
}
47
- return children;
58
+ var childInstances = {};
59
+ traverseAllChildren(nestedChildNodes, instantiateChild, childInstances);
60
+ return childInstances;
61
},
62
63
/**