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

Fix switching Priority Mode with an active draft message from crashing app #7907

Merged
merged 11 commits into from
Mar 4, 2022

Conversation

ctkochan22
Copy link
Contributor

@ctkochan22 ctkochan22 commented Feb 25, 2022

@Expensify/pullerbear
cc @marcaaron

Details

This was a tricky bug to find. I'm mostly worried about regression so ideally we can really test this thoroughly

Fixed Issues

$ #7810
$ #7811

Tests / QA Steps

Fix tests

  1. Go to Settings -> Preferences. Change the priority mode to "#focus". Verify that the LHN condenses
  2. Then change the priority mode back to "Most Recent". Verify that the LHN expands
  3. Now go back to the chat and type text in a chat. Verify that that user now has a draft "pencil" icon
  4. Go back to Settings -> Preferences. Change the priority mode to "#focus". Verify that the LHN condenses, and the user with the draft still has a pencil.
    • This is where the app crashes without this change
  5. Change the priority mode to "Most Recent". Verify that the LHN expands
    APfitvvVAQ

Regression
Part of the bug was introduced in this PR (#6084), so lets take their tests word for word and test them

  1. Type text in the chat without sending it
    • Verify that you see the pencil next to the name and the order does not re-order
  2. Type text in chat and send it
    • Verify that the pencil appears and disappears once its sent. The LHN order should change. User that you messaged should go to the top (but below pinned users)
  3. Type text in he chat positioned in the middle. Then click on another contact.
    • The pencil icon should remain. User with an unsent draft should move to the top
  4. Go to the user that had the draft message and delete it.
    • Pencil icon should disappear and order should re-order
  5. As a different user, message the first user. The message sender should move to the top
    • Verify that the message sender moves to the top

PR Review Checklist

Contributor (PR Author) Checklist

  • I made sure to pull main before submitting my PR for review
  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I clearly indicated the environment tests should be run in (Staging vs Production)
  • I wrote testing steps that cover success & fail scenarios (if applicable)
  • I ran the tests & they passed on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified there are no console errors related to changes in this PR
  • I followed proper code patterns (see Reviewing the code)
    • I added comments when the code was not self explanatory
    • I put all copy / text shown in the product in all src/languages/* files (if applicable)
    • I followed proper naming convention for platform-specific files (if applicable)
    • I followed style guidelines (in Styling.md) for all style edits I made
  • I followed the guidelines as stated in the Review Guidelines

PR Reviewer Checklist

  • I verified the Author pulled main before submitting the PR
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the testing environment is mentioned in the test steps
  • I verified testing steps cover success & fail scenarios (if applicable)
  • I verified tests pass on all platforms & I tested again on all platforms
  • I checked that screenshots or videos are included for tests on all platforms
  • I verified there are no console errors related to changes in this PR
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified comments were added when the code was not self explanatory
    • I verified any copy / text shown in the product was added in all src/languages/* files (if applicable)
    • I verified proper naming convention for platform-specific files was followed (if applicable)
    • I verified style guidelines were followed
  • I verified that this PR follows the guidelines as stated in the Review Guidelines

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

Above

Desktop

https://recordit.co/hU5T21bVYm

iOS

https://recordit.co/sE7YS8nxIo

Android

https://recordit.co/2Tt6hj5jw2

@ctkochan22 ctkochan22 requested a review from a team as a code owner February 25, 2022 05:45
@ctkochan22 ctkochan22 self-assigned this Feb 25, 2022
@MelvinBot MelvinBot requested review from pecanoro and removed request for a team February 25, 2022 05:46
@ctkochan22
Copy link
Contributor Author

Actually, filter is not the solution. We use map because we need to replace old report object with new ones

@ctkochan22 ctkochan22 changed the title [HOLD] Fix switching Priority Mode with an active draft message from crashing app Fix switching Priority Mode with an active draft message from crashing app Feb 28, 2022
Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

Changes look good, but I did have a question or two. I found this file really hard to follow and think it could be improved, but no expectations to do that in this PR. 😄

unreadReports: SidebarLinks.getUnreadReports(props.reports || {}),
};
}

static getDerivedStateFromProps(nextProps, prevState) {
const shouldReorder = SidebarLinks.shouldReorder(nextProps, prevState.orderedReports, prevState.currentlyViewedReportID, prevState.unreadReports);
const switchingPriorityModes = nextProps.priorityMode !== prevState.priorityMode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we compare this.props.priorityMode with nextProps.priorityMode and leave state out of the equation entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this.props isn't available within getDerivedStateFromProps for some reason.

Out of curiosity, why do you want to leave state out of the equation? Bc we are not using state.priorityMode anywhere else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Bc we are not using state.priorityMode anywhere else

That, and we're just setting whatever is in props directly to state which usually means it does not need to be there. If we need to track the updates of a prop then we can just look at the prop.

Anyway, I think we are basically stuck at this point and would need to refactor the entire component to fix this. I'm remembering now that this is a static method and can't access the component instance at all.

There are some good explanations here that go into why we should not use this here (but hopefully the explanation I just gave also makes sense).

https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html

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 would actually be super interested in refactoring the entire component

However, should I scale back some of the changes then to get somethign merged now? Right now the undefineds are causing a crash, or requires a hard refresh

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah! I created this issue here - feel free to steal it from me.

But agree we should just fix this for now :D

src/pages/home/sidebar/SidebarLinks.js Show resolved Hide resolved
src/pages/home/sidebar/SidebarLinks.js Show resolved Hide resolved
src/pages/home/sidebar/SidebarLinks.js Show resolved Hide resolved
src/pages/home/sidebar/SidebarLinks.js Outdated Show resolved Hide resolved
@ctkochan22
Copy link
Contributor Author

Updated. I tested it on all platforms, videos of the tests above. Definitely encouraged to test though! Added a lot of regression testing as well

@marcaaron marcaaron dismissed their stale review March 1, 2022 16:58

LGTM now and agree on the plan forward.

@ctkochan22
Copy link
Contributor Author

@pecanoro friendly bump!

@pecanoro pecanoro merged commit 5ceaf62 into main Mar 4, 2022
@pecanoro pecanoro deleted the ckt_focus_fixDraft branch March 4, 2022 20:45
@OSBotify
Copy link
Contributor

OSBotify commented Mar 4, 2022

✋ 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 @pecanoro in version: 1.1.42-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @chiragsalian in version: 1.1.42-6 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 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.

None yet

4 participants