-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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: Composer does not refocus when click the same chat #24360
Fix: Composer does not refocus when click the same chat #24360
Conversation
@Santhosh-Sellavel Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
if (this.props.isCreateMenuOpen || this.props.currentReportID === option.reportID || (this.props.isSmallScreenWidth && Navigation.getTopmostReportId())) { | ||
if ( | ||
this.props.isCreateMenuOpen || | ||
(!this.props.isSmallScreenWidth && this.props.isActiveReport(option.reportID)) || |
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.
On small screen devices, when we navigate from report screen back to LHN, the currentReportID
is set to undefined
. But as prevCurrentReportID
is saved in a ref, we cannot update the ref to undefined
which leads to prevCurrentReportID
unchanged and thus cannot navigate back to that same report again.
Also, the expected behavior only works on large screen devices so I added this check.
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 is one important issue with the code, please address
const prevCurrentReportID = usePrevious(currentReportID); | ||
const isActiveReport = useCallback((reportID) => prevCurrentReportID === reportID, [prevCurrentReportID]); |
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.
Sorry, I know I proposed using usePrevious
, but it's actually not a good idea here as it directly returns the value (ref.current). Plus its incorrect as it indeed returns the previous value.
This way the callback gets recreated for each currentReportID, which is something we want to avoid.
So instead you might want to consider the following code:
const prevCurrentReportID = usePrevious(currentReportID); | |
const isActiveReport = useCallback((reportID) => prevCurrentReportID === reportID, [prevCurrentReportID]); | |
const currentReportIDRef = useRef(currentReportID); | |
currentReportIDRef.current = currentReportID; | |
const isActiveReport = useCallback((reportID) => currentReportIDRef.current === reportID, []); |
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 lot! I agree.
…composer-refocus-when-click-the-same-chat
@@ -15,6 +15,7 @@ import CONST from '../../../CONST'; | |||
import useLocalize from '../../../hooks/useLocalize'; | |||
import styles from '../../../styles/styles'; | |||
import withNavigationFocus from '../../../components/withNavigationFocus'; | |||
import usePrevious from '../../../hooks/usePrevious'; |
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.
LINT
There were some changes in #24204 that re-introduced the It's recommended that we should handle That's my fault. I was the author of the PR but not aware of that. ProposalWe have 2 goals here:
Solution
App/src/pages/home/sidebar/SidebarLinks.js Lines 231 to 243 in a03a21d
this.props.isLoading && <OptionsListSkeletonView shouldAnimate |
Bump @ArekChr to take a look. |
@tienifr Where exactly will |
@ArekChr @Santhosh-Sellavel #24204 has caused a regression and will be fixed in #24619, so we will continue the discussion in that PR. Its point is to remove the use of |
@tienifr Please add Hold to the PR title thanks! |
Update: PR has moved to #25159. |
@Santhosh-Sellavel As #25159 was merged, I think we're ready for review again! |
@@ -81,6 +81,10 @@ function SidebarLinksData({isFocused, allReportActions, betas, chatReports, curr | |||
return reportIDsRef.current || []; | |||
}, [allReportActions, betas, chatReports, currentReportID, policies, priorityMode, isLoading]); | |||
|
|||
const currentReportIDRef = useRef(currentReportID); | |||
currentReportIDRef.current = currentReportID; |
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.
Is this value assignment needed? currentReportID is set on the line above as the initial value
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.
Without that assignment, the ref would not be updated when currentReportID
changes, I think.
Bump @Santhosh-Sellavel |
const currentReportIDRef = useRef(currentReportID); | ||
currentReportIDRef.current = currentReportID; | ||
const isActiveReport = useCallback((reportID) => currentReportIDRef.current === reportID, []); |
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.
Can't we simplify the block like this?
const isActiveReport = useCallback((reportID) => currentReportID === reportID, [currentReportID]);
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 have mentioned in my proposal:
For the callback, in order not to use currentReportID as a dependency of the callback, which leads to the callback re-render too often, we should save it in a ref instead.
@tienifr Also I checked the issue no longer exists on Main/Production/Staging. Screen.Recording.2023-09-04.at.2.39.15.AM.mov |
@Santhosh-Sellavel I think the main purpose of this PR is to completely get rid of |
@tienifr Then please update the PR description properly. Elaborate how performance was improved |
I've updated. |
Reviewer Checklist
Screenshots/VideosWeb & DesktopScreen.Recording.2023-09-04.at.2.31.24.AM.movMobile Web - Chrome & Mobile Web - SafariScreen.Recording.2023-09-04.at.10.56.26.PM.moviOSScreen.Recording.2023-09-04.at.11.02.58.PM.movAndroidNote: Some Issues with My Android, but that shouldn't be blocking this one, Thanks! |
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.
LGTM tests well!
@MonilBhavsar All yours, please test on Android if possible! |
Bump @MonilBhavsar |
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.
Works fine on android
Screen.Recording.2023-09-06.at.12.46.28.PM.mov
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
Probabaly could have waited after the conferences, @Santhosh-Sellavel @tienifr please be available over next 24 hours for any potential deploy blockers, thanks! |
Sorry My bad, forgot to mention about freeze to @MonilBhavsar |
🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 1.3.65-0 🚀
|
🚀 Deployed to production by https://github.com/mountiny in version: 1.3.65-7 🚀
|
🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 1.3.66-0 🚀
|
🚀 Deployed to production by https://github.com/Beamanator in version: 1.3.66-3 🚀
|
Details
Composer does not refocus when click the same chat. Should not use
currentReportID
directly inSidebarLinks
component to check for the active report as it may affect performance (context: #21022 (comment)). This PR gets rid ofwithCurrentReportID
and lifts the check up toSidebarLinksData
.Fixed Issues
$ #23676
PROPOSAL: #23676 (comment)
Tests
Offline tests
NA
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
Screen.Recording.2023-08-10.at.17.48.44.mov
Mobile Web - Chrome
Screen.Recording.2023-08-10.at.18.25.05.mov
Mobile Web - Safari
Screen.Recording.2023-08-10.at.18.16.49.mov
Desktop
Screen.Recording.2023-08-10.at.18.25.47.mov
iOS
Screen.Recording.2023-08-10.at.18.16.09.mov
Android
Screen.Recording.2023-08-10.at.18.10.27.mov