-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Conversation
} | ||
|
||
if (isValidConfigRefOrKey(config, 'ref')) { |
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.
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.
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.
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); |
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.
What are the freezes for? (I guess they were here already too…)
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.
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).
Can you inline all the |
@gaearon updated the pull request. |
For the changelog:
|
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).
Fix issues introduced by createElement() warning (cherry picked from commit 2d74280)
Fix issues introduced by createElement() warning (cherry picked from commit 2d74280)
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 increateElement()
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.
ref
orkey
that areundefined
in development (@gaearon in Fix issues introduced by createElement() warning #6880)cloneElement
(@ericmatthys in Do not clone key and ref getter props #6268)