-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Use shallowEqual in shouldComponentUpdate #940
Conversation
@@ -1,6 +1,7 @@ | |||
import React, { Component, PropTypes } from 'react' | |||
import invariant from 'invariant' | |||
import createConnectedField from './ConnectedField' | |||
import shallowEqual from 'fbjs/lib/shallowEqual' |
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.
fbjs
isn't a redux-form
dependency. You can access it because you are using npm@3
.
One drawback of this change is that it will rerender a lot more! render() {
return (
<Field name="color" component="select">
<option value="r">Red</option>
<option value="g">Green</option>
<option value="b">Blue</option>
</Field>
)
} When |
I'm fine with a dep on Please do |
Perhaps The tests should be sure that it only rerenders once when the |
@erikras I think |
Same behavior when using a |
@ooflorent react-addons-shallow-compare takes 3 parameters which include |
@leesiongchan Since What to you think @erikras about the addon? |
👍 Sounds good. |
But this change to |
61ade5c
to
edf1fe2
Compare
@@ -70,6 +70,7 @@ | |||
"lodash-webpack-plugin": "^0.3.0", | |||
"mocha": "^2.4.5", | |||
"react": "^15.0.0", | |||
"react-addons-shallow-compare": "^15.0.0", |
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.
Should be added to peerDependencies
as well, or dependencies
. I don't know what's the best practice on this...
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.
ping @erikras
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 critical. If you don't add it to dependencies
or peerDependencies
, the package will be broken.
No, |
edf1fe2
to
bc5e87c
Compare
Updated. |
bc5e87c
to
e688126
Compare
@@ -43,7 +43,8 @@ | |||
"hoist-non-react-statics": "^1.0.5", | |||
"invariant": "^2.2.1", | |||
"is-promise": "^2.1.0", | |||
"lodash": "^4.12.0" | |||
"lodash": "^4.12.0", | |||
"react-addons-shallow-compare": "^15.0.0" |
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.
@ooflorent I think is more appropriate to add to dependency compare to peer. @erikras Let me know if I am wrong.
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'm no npm expert, but I would think it belongs in dependencies
.
e688126
to
f3cd1ea
Compare
Updated. |
@@ -23,7 +24,7 @@ const createConnectedFieldArray = ({ | |||
|
|||
class ConnectedFieldArray extends Component { | |||
shouldComponentUpdate(nextProps) { | |||
return size(this.props.value) !== size(nextProps.value) | |||
return shallowCompare(this, nextProps) |
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.
Are you sure for this one? cc @erikras
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.
Discussed on above. Check here
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'm pretty sure. I think this will fix #931.
@leesiongchan, can you write a test where there is a _error
validation error for the array based on some quality of the values inside the array (e.g. if none of them have values), and verify that the array component rerenders when the error appears or disappears?
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.
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.
Yes.
f3cd1ea
to
8d6090a
Compare
8d6090a
to
da6720c
Compare
Published as |
@leesiongchan and @ooflorent, as you may get an earlier start on your Friday than I... The examples have been giving me Thanks! |
Can't see the problem too :'( |
@erikras I can't reproduce the issue. I did a fresh install and ran the builds and test suites and everything worked fine. |
Okay. I swear I was Thanks for confirming my insanity. 😄 👍 |
Maybe you were hitting Babel's cache of webpack's one |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you think it makes sense to use
shallowEqual
or even remove the entireshouldComponentUpdate
asField
should be treated as a simple component to connects form's state and soshouldComponentUpdate
shouldn't be part of the job.Fixes #936