The library for web and native user interfaces.
Assign the same keys if it's a single nested array or not
If you specify a single array, we didn't prefix the keys with 0. If you later add children, the first array won't have the same key.
CommitSyncScript committed
Jun 7, 2013 at 22:04 UTC
7e7579e1bafcbee07751562abc7ae64386978cff
3 files changed
+17
-12
src/core/ReactComponent.js
+1
-1
@@ -87,7 +87,7 @@ function tryToReuseArray(children) {
87
for (var i = 0; i < children.length; i++) {
88
var child = children[i];
89
if (isEmptyChild(child)) return false;
90
- assignKey('', child, i);
90
+ assignKey('0', child, i);
91
}
92
return true;
93
}
src/core/__tests__/ReactIdentity-test.js
+11
-8
@@ -67,8 +67,8 @@ describe('ReactIdentity', function() {
67
React.renderComponent(instance, document.createElement('div'));
68
var node = instance.getDOMNode();
69
reactComponentExpect(instance).toBeDOMComponentWithChildCount(2);
70
- checkId(node.childNodes[0], '.reactRoot[0].[apple]');
71
- checkId(node.childNodes[1], '.reactRoot[0].[banana]');
70
+ checkId(node.childNodes[0], '.reactRoot[0].[0:apple]');
71
+ checkId(node.childNodes[1], '.reactRoot[0].[0:banana]');
72
});
73
74
it('should use instance identity', function() {
@@ -89,12 +89,15 @@ describe('ReactIdentity', function() {
89
React.renderComponent(instance, document.createElement('div'));
90
var node = instance.getDOMNode();
91
reactComponentExpect(instance).toBeDOMComponentWithChildCount(3);
92
- checkId(node.childNodes[0], '.reactRoot[0].[wrap1]');
93
- checkId(node.childNodes[0].firstChild, '.reactRoot[0].[wrap1].[squirrel]');
94
- checkId(node.childNodes[1], '.reactRoot[0].[wrap2]');
95
- checkId(node.childNodes[1].firstChild, '.reactRoot[0].[wrap2].[bunny]');
96
- checkId(node.childNodes[2], '.reactRoot[0].[2]');
97
- checkId(node.childNodes[2].firstChild, '.reactRoot[0].[2].[chipmunk]');
92
+ checkId(node.childNodes[0], '.reactRoot[0].[0:wrap1]');
93
+ checkId(
94
+ node.childNodes[0].firstChild,
95
+ '.reactRoot[0].[0:wrap1].[0:squirrel]'
96
+ );
97
+ checkId(node.childNodes[1], '.reactRoot[0].[0:wrap2]');
98
+ checkId(node.childNodes[1].firstChild, '.reactRoot[0].[0:wrap2].[0:bunny]');
99
+ checkId(node.childNodes[2], '.reactRoot[0].[0:2]');
100
+ checkId(node.childNodes[2].firstChild, '.reactRoot[0].[0:2].[0:chipmunk]');
101
});
102
103
it('should let restructured components retain their uniqueness', function() {
src/utils/__tests__/mapChildren-test.js
+5
-3
@@ -75,7 +75,7 @@ describe('mapChildren', function() {
75
76
expect(mapFn).toHaveBeenCalledWith(simpleKid, 'simple', 0);
77
expect(rendered.props.children[0]).toBe(simpleKid);
78
- expect(rendered.props.children).toHaveKeys(['simple']);
78
+ expect(rendered.props.children).toHaveKeys(['0:simple']);
79
});
80
81
it('should pass key to returned component', function() {
@@ -94,7 +94,7 @@ describe('mapChildren', function() {
94
95
expect(rendered.props.children[0]).not.toBe(simpleKid);
96
expect(rendered.props.children[0].props.children[0]).toBe(simpleKid);
97
- expect(rendered.props.children).toHaveKeys(['simple']);
97
+ expect(rendered.props.children).toHaveKeys(['0:simple']);
98
expect(rendered.props.children[0].props.children).toHaveKeys(['simple']);
99
});
100
@@ -126,6 +126,8 @@ describe('mapChildren', function() {
126
expect(mapFn).toHaveBeenCalledWith(kidTwo, '0:two', 1);
127
expect(mapFn).toHaveBeenCalledWith(kidThree, '0:three', 2);
128
expect(rendered.props.children).not.toEqual(instance.props.children);
129
- expect(rendered.props.children).toHaveKeys(['0:one', '0:two', '0:three']);
129
+ expect(rendered.props.children).toHaveKeys([
130
+ '0:0:one', '0:0:two', '0:0:three'
131
+ ]);
132
});
133
});