Skip to content
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

Merged
merged 1 commit into from
Sep 8, 2014
Merged

Conversation

syranide
Copy link
Contributor

@syranide syranide commented Aug 3, 2014

Fix for #1962

Moves wrapping with ReactTextComponent to flattenChildren 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 use cloneWithProps without all components remounting).

@syranide
Copy link
Contributor Author

syranide commented Aug 3, 2014

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') {
Copy link
Collaborator

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.

Copy link
Contributor Author

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)

@sebmarkbage
Copy link
Collaborator

Love this. @zpao, if this passes our internal test process, can we pull this in?

@syranide
Copy link
Contributor Author

syranide commented Aug 4, 2014

@sebmarkbage Quick poll on your thoughts of #1989
https://github.com/syranide/react/commit/52d96624c3100c28312c0ccc6982aca87bf284a3#diff-5697274a51c77d8781a739f192ceca25 (check last file)

It's a super-simple fix that merges adjacent ReactTextComponents and neatly isolated in flattenChildren (it's possible to hide the var in traverseContext to make it re-entrant, but that should never ever matter).

@syranide
Copy link
Contributor Author

Rebased

@sebmarkbage
Copy link
Collaborator

Will pull this in on Monday. Ping me if I forget.

@syranide
Copy link
Contributor Author

@sebmarkbage You forgot to remind me to remind you :)

@syranide syranide mentioned this pull request Sep 4, 2014
4 tasks
);
for (var key in children) {
if (children.hasOwnProperty(key)) {
var nextName = (
Copy link
Member

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.

@syranide
Copy link
Contributor Author

syranide commented Sep 8, 2014

@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.

@zpao
Copy link
Member

zpao commented Sep 8, 2014

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 :)

zpao added a commit that referenced this pull request Sep 8, 2014
Don't wrap values with ReactTextComponent in traverseAllChildren (cloneWithProps)
@zpao zpao merged commit f3c6470 into facebook:master Sep 8, 2014
@syranide syranide deleted the tacfix branch September 8, 2014 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants