fix: expense chat doesn't scroll to bottom when we create a distance request#39685
fix: expense chat doesn't scroll to bottom when we create a distance request#39685aldo-expensify merged 7 commits intoExpensify:mainfrom
Conversation
|
@dukenv0307 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] |
src/libs/actions/IOU.ts
Outdated
| API.write(WRITE_COMMANDS.CREATE_DISTANCE_REQUEST, parameters, onyxData); | ||
| Navigation.dismissModal(isMoneyRequestReport ? report.reportID : chatReport.reportID); | ||
| Report.notifyNewAction(chatReport.reportID, userAccountID); | ||
| const activeReportID = isMoneyRequestReport ? report.reportID : chatReport.reportID; |
There was a problem hiding this comment.
move that line at the beginning and use it to prevent duplicated code
|
@nkdengineer Can you update |
|
@dukenv0307 I updated your suggestions. |
|
Code looks good, will start to record videos in a hour |
Reviewer Checklist
Screenshots/VideosAndroid: Nativeweb-resize.mp4Android: mWeb Chromeweb-resize.mp4iOS: Nativeweb-resize.mp4iOS: mWeb Safariweb-resize.mp4MacOS: Chrome / Safariweb-resize.mp4MacOS: Desktopweb-resize.mp4 |
|
Tests well |
aldo-expensify
left a comment
There was a problem hiding this comment.
I think the ref value should be updated outside
| } | ||
| previousLastIndex.current = lastActionIndex; | ||
| reportActionSize.current = sortedVisibleReportActions.length; | ||
| hasNewestReportActionRef.current = hasNewestReportAction; |
There was a problem hiding this comment.
@aldo-expensify We update hasNewestReportActionRef whenever hasNewestReportAction is changed in this useEffect so I think it will not out of sync, as you see we also update other ref like previousLastIndex, reportActionSize in this useEffect.
There was a problem hiding this comment.
They are updated in different parts of the lifecycle:
hasNewestReportActionchanges during renderinghasNewestReportActionRefchanges when evaluatinguseEffects
I'm not familiar enough with the react architecture to be sure that scrollToBottomForCurrentUserAction will never be called in between rendering and useEffects when listening to a "new action event" (I haven't looked at the implementation in Report.subscribeToNewActionEvent).
Are you 100% that javascript won't process any other js code (including event listeners) between those two parts of the react lifecycle (rendering/side effects)?
Even if you are sure of the above, I still find it more messy to update this ref here if it is supposed to be in sync with the hasNewestReportAction.
There was a problem hiding this comment.
@aldo-expensify @nkdengineer scrollToBottomForCurrentUserAction can be called in between rendering and useEffects. But, the synchronization time between ref and hasNewestReportAction is too small, and hasNewestReportAction is not changed frequently. Besides, we're updating the ref in useEffect most places in our App, so I think it's ok.
I just don't want to update the ref every time the page re-renders and make codes consistency. Wdyt?
There was a problem hiding this comment.
I agree with that the window is small, but why take the risk?
Besides, we're updating the ref in useEffect most places in our App, so I think it's ok.
It may be a bad pattern? 🤷
I just don't want to update the ref every time the page re-renders and make codes consistency. Wdyt?
What is the problem of updating during rendering? I'm sure there is not performance issue, and for me it is more visible to update it next to where you defined and initialized the variable you are copying. Putting it a useEffect makes the code less readable IMO. There may be reasons to do it in other places, but I don't see one here.
There was a problem hiding this comment.
@nkdengineer Alright, that makes sense to me now, can you update the PR based on @aldo-expensify's suggestion above?
There was a problem hiding this comment.
Thanks, that also makes sense to me now.
There was a problem hiding this comment.
@aldo-expensify @dukenv0307 I updated to update the ref whenever re-rendering.
There was a problem hiding this comment.
@nkdengineer @dukenv0307 It looks like the refactor has caused a regression here.
I am not sure if I understand why this refactor was needed to fix this issue.
Can you please help me understand this?
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/aldo-expensify in version: 1.4.63-0 🚀
|
|
🚀 Deployed to production by https://github.com/mountiny in version: 1.4.63-21 🚀
|
Details
Fixed Issues
$ #39198
PROPOSAL: #39198 (comment)
Tests
Offline tests
Same as above
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
android-resize.mp4
Android: mWeb Chrome
android-mweb-resize.mp4
iOS: Native
ios-resize.mp4
iOS: mWeb Safari
ios-mweb-resize.mp4
MacOS: Chrome / Safari
web-resize.mp4
MacOS: Desktop
desktop-resize.mp4