-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Plans: check if selectedSite exists before checking for domain credit #5089
Conversation
@@ -335,7 +335,7 @@ export const List = React.createClass( { | |||
|
|||
export default connect( ( state, ownProps ) => { | |||
return { | |||
hasDomainCredit: hasDomainCredit( state, ownProps.selectedSite.ID ) | |||
hasDomainCredit: ownProps.selectedSite && hasDomainCredit( state, ownProps.selectedSite.ID ) |
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 this be done in current-site/notice.jsx 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.
Yes a similar check, or enforce an object being passed through in propTypes:
propTypes: {
site: React.PropTypes.object.isRequired
},
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'd prefer the latter of an explicit prop, but I added the former in 48a7bd2 for a quick fix
87dcd09
to
48a7bd2
Compare
@@ -92,7 +92,7 @@ const SiteNotice = React.createClass( { | |||
|
|||
export default connect( ( state, ownProps ) => { | |||
return { | |||
hasDomainCredit: hasDomainCredit( state, ownProps.site.ID ) | |||
hasDomainCredit: !! ownProps.site && hasDomainCredit( state, ownProps.site.ID ) |
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.
Isn't the convention to use Boolean()
instead of !!
?
FWIW, we usually just check only if it's falsy:
hasDomainCredit: ownProps.site && hasDomainCredit( state, ownProps.site.ID )
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.
It's a common js usage. I think its a bit more clear for !! to denote that we're testing for truthyness. The Boolean conversion can sometimes return unexpected things, like so:
Boolean("false"); // still returns true
Thanks for fixing it Kerry! I think one way to reproduce it is to sandbox the API (or to make API calls very slow :)). |
Potential fix for #5084. This adds bulletproofing before we check if a site has domain credits.
I wasn't able to reproduce the original issue, but we should handle this case anyway.
cc @fabianapsimoes @stephanethomas @rralian