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(issue): Make sure the right repository is fetched #332
Conversation
@@ -160,10 +159,11 @@ class Issue extends Component { | |||
issueURLParam ? issueCommentsURL : issueParam.comments_url | |||
), | |||
]).then(() => { | |||
const issue = this.props.issue; |
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.
@chinesedfan can as earlier receive variable issue
(144 line)? Then you just do not need this line.
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.
@lex111 No, we should read after those 2 promises, getIssueFromUrlByDispatch
and getIssueCommentsByDispatch
, are fulfilled. Or this.props.issue
may refer to the previous wrong issue.
That's what I mean "the fetched issue". Sorry for my poor English pr description.
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.
Nope that shouldn't be the case :)
In the top of the file, we're mapping parts of our state object into our props. So issue
isn't a fixed object parameter here, but will always reflect what's happening with state. If getIssueFromUrlByDispatch
and/or getIssueCommentsByDispatch
update state.issue
where state is our Redux container - our issue props will always reflect this. So we should be good with leaving it as part of the destructuring in line 144 😃
Please let me know to clarify this if it's still not making any sense to you mate
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.
Right. this.props.issue
will always be updated by redux, but in line 144, issue
is just a temporary local variable destructed from this.props
, which will never be updated.
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 I'm sorry, you're right here. It gets modified in the promise call and our current local variable isn't really going to reflect this.
Cheers thank you mate, and I'm sorry for causing any confusion 😞
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.
Thanks a million for this and appreciate you catching exactly what was causing the error @chinesedfan 🎉
Left one comment per @lex111's suggestion, otherwise this is solid :)
@@ -160,10 +159,11 @@ class Issue extends Component { | |||
issueURLParam ? issueCommentsURL : issueParam.comments_url | |||
), | |||
]).then(() => { | |||
const issue = this.props.issue; |
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.
Nope that shouldn't be the case :)
In the top of the file, we're mapping parts of our state object into our props. So issue
isn't a fixed object parameter here, but will always reflect what's happening with state. If getIssueFromUrlByDispatch
and/or getIssueCommentsByDispatch
update state.issue
where state is our Redux container - our issue props will always reflect this. So we should be good with leaving it as part of the destructuring in line 144 😃
Please let me know to clarify this if it's still not making any sense to you mate
src/issue/screens/issue.screen.js
Outdated
repository.full_name !== | ||
issueParam.repository_url.replace(`${apiRoot}/repos/`, '') |
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.
So this was the culprit. It looks like issueParam
, unlike props.issue
, is actually obtained from the navigation.params so it's not being updated when those calls within Promise.all
are fired
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.
Suppose we have visited repository A, and try to visit another issue/pr of repository B. props.repository
will refer to A at first. issueParam.repository_url
will refer to B.
The basic logic is correct here. But issueParam.repository_url
does not always have value, which may be caused by issueParam
itself or issueParam.repository_url
as my PR description says.
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.
@housseindjirdeh Any feedbacks? :)
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.
Thank you so much @chinesedfan, and apologies for not getting to this sooner!
Fixed #315 and #318.
In fact, #318 is fixed partially by #317, as
getContributorsByDispatch
is not called correctly. But the main problem is that the right repository is not always fetched.If visit
issue.screen
from:issueURLParam
has value, whileissueParam
is undefined (Wrong issue/pr permissions when visit from notifications tab #315)issueParam
has value, whileissueURLParam
is undefinedissueParam.repository_url
is undefined (Incorrect contributors when trying to @ in issues #318)So I use
props.issue.repository_url
to check, which belongs to the fetched issue.