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

Refactor the componentDidUpdate method for ReportActionCompose #4768

Merged
merged 5 commits into from
Aug 30, 2021

Conversation

mountiny
Copy link
Contributor

@mountiny mountiny commented Aug 20, 2021

Details

To resolve a StagingDeployBlocker, we have introduced some changes which need some refactoring. How to refactor has been discussed and decided in this thread here. Look there for more details.

Fixed Issues

Tests

Just repeat the action performed steps from this issue #4756 and make sure it all works as expected.

QA Steps

  1. Navigate to a conversation
  2. Write something in compose box
  3. Use ctrl+k command
  4. Select another conversation
  5. Verify that nothing is displayed in compose box if the selected conversation didn't have a draft
  6. Use ctrl+k command to switch back to the first conversation.
  7. Verify that the draft message in the compose box is shown.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

Mobile Web

Desktop

iOS

Android

@mountiny mountiny requested a review from a team August 20, 2021 17:51
@mountiny mountiny self-assigned this Aug 20, 2021
@MelvinBot MelvinBot requested review from joelbettner and removed request for a team August 20, 2021 17:51
@mountiny
Copy link
Contributor Author

mountiny commented Aug 20, 2021

@marcaaron My theory based on what I have observed when testing it is that the reportID is fetched from route here and passed down to the ReportActionCompose. However, the report which holds the comment we need is not updated at that same time as the route changes. In console I could see ~2-3 calls of componentDidUpdate in ReportActionCompose with the previous report while the reportID has already been updated (as a consequence the draft comment from previous message is populated into the input).

Isn't it that the reportID fetched from route is from the Navigation whereas report is from Onyx which can take slightly longer to switch?

@marcaaron marcaaron requested review from marcaaron and removed request for joelbettner August 20, 2021 18:12
@marcaaron
Copy link
Contributor

Isn't it that the reportID fetched from route is from the Navigation whereas report is from Onyx which can take slightly longer to switch?

Yes that makes sense to me. It should be like 1 tick behind because Onyx is asynchronous. Is that what you're asking?

this.textInput.setNativeProps({text: this.props.comment});
// If we switch the reports, make sure to update the composer comment
const reportChanged = this.props.report.reportID !== prevProps.report.reportID;
if (reportChanged) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should use an early return like

if (!reportChanged) {
    return;
}

this.updateComment(this.props.comment);

Copy link
Contributor

Choose a reason for hiding this comment

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

Also reportChanged does not need a variable just put the comparison into the if case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the componentDidUpdate accordingly. Since the same logic is also used in ReportScreen, I have updated it there too to follow the same pattern or early return for consistency :)

@mountiny mountiny requested a review from a team as a code owner August 25, 2021 17:36
@MelvinBot MelvinBot requested review from bondydaa and removed request for a team August 25, 2021 17:37
@mountiny mountiny removed the request for review from bondydaa August 25, 2021 17:39
@mountiny
Copy link
Contributor Author

Sorry for the ping, Bondy, that was some bug, I have not assigned PullerBear again :/

It should be like 1 tick behind because Onyx is asynchronous. Is that what you're asking?

@marcaaron Yes, that is what I meant. The Onyx report change is always a bit behind the route change.

// so we need to update the comment manually.
if (prevProps.comment !== this.props.comment) {
this.textInput.setNativeProps({text: this.props.comment});
// If we switch the reports, make sure to update the composer comment; otherwise return early
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB comments should explain why not what we are doing in the code. so I would suggest removing the otherwise return early and instead a because... explaining why we need to update the composer comment:

Suggested change
// If we switch the reports, make sure to update the composer comment; otherwise return early
// If we switch the reports, make sure to update the composer comment because [we don't want to leave old data around] [we shouldn't copy what a user had types in one place to another]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, I was not sure about that comment actually, thank you for bringing it up! I will update it just now.

this.storeCurrentlyViewedReport();
// If we do not switch between reports, return early
if (this.props.route.params.reportID === prevProps.route.params.reportID) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB, I know this was probably added since you noticed that the style doesn't match what I asked for in another comment. But since this change doesn't have anything to do with the current change I wonder if a better way to handle this would be to:

  1. Create a new issue calling out there there are places where early returns are not used
  2. Follow up to audit existing if blocks to see which are not using early returns and fix them

I'm not asking you to do it since we don't really have any rules or conventions about this. Some feel like it's fine to fix things that are wrong when you see them and others (like me) prefer to keep only material changes in PRs so that context is preserved and no one needs to ask why something was done. I don't think there is a "right way", so mostly just sharing this perspective.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really appreciate you sharing this with me. This helps me a lot 🙇 I do agree it is not ideal to add changes and fixes to PR where it might be unrelated and uncalled for. I haven't realized it now, but I will definitely try to keep this on mind for future! It will make for clearer and easier to follow issues and PR for sure 🙌

I agree with you on the proposed process how to handle such a change, although as you stated, I think before creating such an investigation issue, we should make sure we update the Styling guidelines accordingly. That way if we fix this bad smell throughout the codebase we will have lesser chances of introducing it again.

Do you think this is work of being added to the styling guide, or it is too nitty-gritty 👀 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW how I view "adjacent style changes" (completely just made that up) like this are to weigh the "pros vs cons" of how bad it might be to have to revert or quickly fix if this breaks something unexpectedly.

I agree this seems like a pretty low risk change so probably fine to leave. But this mean you should be on the look out for any messages in #api-errors, #qa, or new GHs from Success that mention anything about weirdness about the report pages.

If you're not willing to be on "high alert" and fix something like that then I'd say only make the change you intended to make and leave the "adjacent style change" alone and spin up a new GH to fix it so that it's properly tested in it's own PR.

I don't think there is a need for a style guide rule or anything since there will be nuances to every PR where sometimes it makes sense to change all "adjacent style changes" and other times it might not make the most sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bondydaa Thank you very much for your 2 cents here! Glad to have another perspective on this 💯

I will keep an eye on those channels! Thanks for the heads up. I think in this case there should not be high risk 🤞 since the logic stays the same, but I totally see what you mean. Even with minor styling changes, we should make sure all the flows are working and no edge case has been omitted 👍

Regarding the styling guide, I see your point. Eventually, informing more and more engineers about this style approach, we might get more of them using it in their code and PR reviews consequently making it standard the organic way.

if (reportChanged) {
this.prepareTransition();
this.storeCurrentlyViewedReport();
// If we do not switch between reports, return early
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment to @bondydaa but if a comment ends up just describing what the code is doing (or is very obvious) then we probably don't need the comment at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, in this case it is actually bit clearer why we check if the reports have changed. I will omit the comment here 👍

@mountiny
Copy link
Contributor Author

@bondydaa @marcaaron Thank you very much for your tips, advice and best practices on this matter. I have pushed some updates, I tried to give a better yet short description of why we update the comment if reportIDs change and I have removed the comment in ReportScreen since it is self-explanatory what the code does there.

Thank you for your reviews 🙌

@mountiny mountiny requested review from bondydaa and marcaaron August 25, 2021 21:54
@marcaaron marcaaron merged commit 36dc811 into main Aug 30, 2021
@marcaaron marcaaron deleted the vit-refactorTheReportActionCompose branch August 30, 2021 19:43
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @marcaaron in version: 1.0.89-0 🚀

platform result
🤖 android 🤖 skipped 🚫
🖥 desktop 🖥 skipped 🚫
🍎 iOS 🍎 skipped 🚫
🕸 web 🕸 skipped 🚫

@isagoico
Copy link

@mountiny @marcaaron Are we good to check this PR off the list? (I'm guessing it's NoQA but wanted to double check)

@roryabraham
Copy link
Contributor

@isagoico I filled in the QA steps here. Can you please perform QA on this?

@isagoico
Copy link

isagoico commented Sep 1, 2021

Just tested it and it was a pass 🎉 checking it off.

@OSBotify
Copy link
Contributor

OSBotify commented Sep 1, 2021

🚀 Deployed to production by @roryabraham in version: 1.0.90-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants