Skip to content

Commit f3c6470

Browse files
committed
Merge pull request #1988 from syranide/tacfix
Don't wrap values with ReactTextComponent in traverseAllChildren (cloneWithProps)
2 parents 61c42cc + 45f8837 commit f3c6470

2 files changed

Lines changed: 40 additions & 34 deletions

File tree

src/utils/flattenChildren.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
"use strict";
2020

21+
var ReactTextComponent = require('ReactTextComponent');
22+
2123
var traverseAllChildren = require('traverseAllChildren');
2224
var warning = require('warning');
2325

@@ -38,7 +40,18 @@ function flattenSingleChildIntoContext(traverseContext, child, name) {
3840
name
3941
);
4042
if (keyUnique && child != null) {
41-
result[name] = child;
43+
var type = typeof child;
44+
var normalizedValue;
45+
46+
if (type === 'string') {
47+
normalizedValue = ReactTextComponent(child);
48+
} else if (type === 'number') {
49+
normalizedValue = ReactTextComponent('' + child);
50+
} else {
51+
normalizedValue = child;
52+
}
53+
54+
result[name] = normalizedValue;
4255
}
4356
}
4457

src/utils/traverseAllChildren.js

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
var ReactDescriptor = require('ReactDescriptor');
2222
var ReactInstanceHandles = require('ReactInstanceHandles');
23-
var ReactTextComponent = require('ReactTextComponent');
2423

2524
var invariant = require('invariant');
2625

@@ -98,16 +97,17 @@ function wrapUserProvidedKey(key) {
9897
*/
9998
var traverseAllChildrenImpl =
10099
function(children, nameSoFar, indexSoFar, callback, traverseContext) {
100+
var nextName, nextIndex;
101101
var subtreeCount = 0; // Count of children found in the current subtree.
102102
if (Array.isArray(children)) {
103103
for (var i = 0; i < children.length; i++) {
104104
var child = children[i];
105-
var nextName = (
105+
nextName = (
106106
nameSoFar +
107107
(nameSoFar ? SUBSEPARATOR : SEPARATOR) +
108108
getComponentKey(child, i)
109109
);
110-
var nextIndex = indexSoFar + subtreeCount;
110+
nextIndex = indexSoFar + subtreeCount;
111111
subtreeCount += traverseAllChildrenImpl(
112112
child,
113113
nextName,
@@ -127,39 +127,32 @@ var traverseAllChildrenImpl =
127127
// All of the above are perceived as null.
128128
callback(traverseContext, null, storageName, indexSoFar);
129129
subtreeCount = 1;
130-
} else if (ReactDescriptor.isValidDescriptor(children)) {
130+
} else if (type === 'string' || type === 'number' ||
131+
ReactDescriptor.isValidDescriptor(children)) {
131132
callback(traverseContext, children, storageName, indexSoFar);
132133
subtreeCount = 1;
133-
} else {
134-
if (type === 'object') {
135-
invariant(
136-
!children || children.nodeType !== 1,
137-
'traverseAllChildren(...): Encountered an invalid child; DOM ' +
138-
'elements are not valid children of React components.'
139-
);
140-
for (var key in children) {
141-
if (children.hasOwnProperty(key)) {
142-
subtreeCount += traverseAllChildrenImpl(
143-
children[key],
144-
(
145-
nameSoFar + (nameSoFar ? SUBSEPARATOR : SEPARATOR) +
146-
wrapUserProvidedKey(key) + SUBSEPARATOR +
147-
getComponentKey(children[key], 0)
148-
),
149-
indexSoFar + subtreeCount,
150-
callback,
151-
traverseContext
152-
);
153-
}
134+
} else if (type === 'object') {
135+
invariant(
136+
!children || children.nodeType !== 1,
137+
'traverseAllChildren(...): Encountered an invalid child; DOM ' +
138+
'elements are not valid children of React components.'
139+
);
140+
for (var key in children) {
141+
if (children.hasOwnProperty(key)) {
142+
nextName = (
143+
nameSoFar + (nameSoFar ? SUBSEPARATOR : SEPARATOR) +
144+
wrapUserProvidedKey(key) + SUBSEPARATOR +
145+
getComponentKey(children[key], 0)
146+
);
147+
nextIndex = indexSoFar + subtreeCount;
148+
subtreeCount += traverseAllChildrenImpl(
149+
children[key],
150+
nextName,
151+
nextIndex,
152+
callback,
153+
traverseContext
154+
);
154155
}
155-
} else if (type === 'string') {
156-
var normalizedText = ReactTextComponent(children);
157-
callback(traverseContext, normalizedText, storageName, indexSoFar);
158-
subtreeCount += 1;
159-
} else if (type === 'number') {
160-
var normalizedNumber = ReactTextComponent('' + children);
161-
callback(traverseContext, normalizedNumber, storageName, indexSoFar);
162-
subtreeCount += 1;
163156
}
164157
}
165158
}

0 commit comments

Comments
 (0)