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

Fix issues introduced by createElement() warning #6880

Merged
merged 10 commits into from
May 26, 2016
Merged

Fix issues introduced by createElement() warning #6880

merged 10 commits into from
May 26, 2016

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented May 25, 2016

This builds on top of #6268.

I fixed a few style nits and indirection in it, and later I realized it introduces a bug in cloneElement(). As I was tracing this bug, I found that it already existed in createElement() in 15.x (#6879).

So I fixed the bug for both cases, added more tests, and shuffled them around to sit in the corresponding files.


ericmatthys and others added 6 commits May 25, 2016 23:02
It currently fails in `createElement` because of #6879 which was introduced in #5744.
It also fails in `cloneElement` because the code with that bug was extracted and shared in 94d0dc6.
This way in other cases both DEV and PROD falls through to the check for undefined.
This fixes #6879 and a similar bug introduced for cloneElement() in 94d0dc6.
}

if (isValidConfigRefOrKey(config, 'ref')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be slower (in prod mode). We should avoid passing around object keys as strings whenever possible because engines can't optimize it as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you fixed this.

@@ -165,7 +165,59 @@ describe('ReactElement', function() {
expect(element.type).toBe(ComponentClass);
expect(element.key).toBe('12');
expect(element.ref).toBe('34');
var expectation = {foo:'56'};
var expectation = {foo: '56'};
Object.freeze(expectation);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the freezes for? (I guess they were here already too…)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea 😄 . They were there and spread like fire. I wouldn’t be surprised if the first freeze was added for a completely unrelated purpose. (Maybe from the pre-element times?)

We don’t want to have different behavior in development and production.
Previously, we used to ignore getters on key/ref in dev, but we’d read them in prod.
Now, we only ignore the getters that we *know* we created so the production logic doesn’t differ.
This fixes an incorrect way of checking introduced in 95373ce (it had no effect).
@sophiebits
Copy link
Collaborator

Can you inline all the var expectation = now that they're only used once each? Otherwise looks great.

@ghost
Copy link

ghost commented May 26, 2016

@gaearon updated the pull request.

@gaearon gaearon merged commit 2d74280 into facebook:master May 26, 2016
@gaearon gaearon deleted the clone-key-ref-props-2 branch May 26, 2016 00:41
@gaearon gaearon added this to the 15.y.z milestone May 26, 2016
@gaearon
Copy link
Collaborator Author

gaearon commented May 26, 2016

@zpao

For the changelog:

enlight added a commit to debugworkbench/hydragon that referenced this pull request May 31, 2016
This version seems to produce some spurious warnings like these:
> Element: `key` is not a prop. Trying to access it will result in
> `undefined` being returned. If you need to access the same value
> within the child component, you should pass it as a different prop.

I'm pretty sure these warnings can be safely ignored and will go away
in the next release (see facebook/react#6880).
zpao pushed a commit to zpao/react that referenced this pull request Jun 8, 2016
Fix issues introduced by createElement() warning
(cherry picked from commit 2d74280)
zpao pushed a commit that referenced this pull request Jun 14, 2016
Fix issues introduced by createElement() warning
(cherry picked from commit 2d74280)
@zpao zpao modified the milestones: 15-next, 15.2.0 Jun 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants