-
Notifications
You must be signed in to change notification settings - Fork 46.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't wrap values with ReactTextComponent in traverseAllChildren (cloneWithProps) #1988
Conversation
cc @zpao @sebmarkbage, this seems straight-forward to me, unless you have other intentions (perhaps we really should just make cloneWithProps use its own traversal code). |
@@ -127,39 +127,32 @@ var traverseAllChildrenImpl = | |||
callback(traverseContext, null, storageName, indexSoFar); | |||
subtreeCount = 1; | |||
} else if (children.type && children.type.prototype && | |||
children.type.prototype.mountComponentIntoNode) { | |||
children.type.prototype.mountComponentIntoNode || | |||
type === 'string' || type === 'number') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of difficult to follow and under-parenthesized. Can we break this apart a bit so that it's easier to read?
Looks logically correct but it would be interesting to see if the order matters for performance here. I.e. if the type string/number/object check matters on real code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (type === 'string' || type === 'number' ||
children.type && children.type.prototype &&
children.type.prototype.mountComponentIntoNode) {
Is a lot more logical perhaps, otherwise a bit more dramatic (but not as fast, not that it should be measurable):
} else {
var isComponent = (
children.type && children.type.prototype &&
children.type.prototype.mountComponentIntoNode
);
if (type === 'string' || type === 'number' || isComponent) {
..
} else if (type === 'object') {
..
Any preference? (I've updated according to the first code as it's a lot better at least)
Love this. @zpao, if this passes our internal test process, can we pull this in? |
@sebmarkbage Quick poll on your thoughts of #1989 It's a super-simple fix that merges adjacent ReactTextComponents and neatly isolated in |
Rebased |
Will pull this in on Monday. Ping me if I forget. |
@sebmarkbage You forgot to remind me to remind you :) |
); | ||
for (var key in children) { | ||
if (children.hasOwnProperty(key)) { | ||
var nextName = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failing lint because these names (nextName
, nextIndex
) are used above. Perhaps just define above the whole conditional.
@zpao Fixed and fixed. Just shout if there's anything else. I can't run the tests for some reason, so I'll just defer to travis for now. |
Thanks. Tests pass and this doesn't seem to have broken any of our other test workflows, so there shouldn't be any more issues :) |
Don't wrap values with ReactTextComponent in traverseAllChildren (cloneWithProps)
Fix for #1962
Moves wrapping with
ReactTextComponent
toflattenChildren
instead, where it belongs.Also very minor code fix-up. Also worth mentioning that the flattening done by
cloneWIthProps
messes with the reactids, so while the idea is to avoid unnecessary allocations I assume, it does affect outcome (i.e, you can't conditionally usecloneWithProps
without all components remounting).