-
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: expense chat doesn't scroll to bottom when we create a distance request #39685
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
@@ -1391,7 +1391,8 @@ function createDistanceRequest( | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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 think the ref value should be updated outside
@@ -226,6 +226,7 @@ function ReportActionsList({ | |||
} | |||
previousLastIndex.current = lastActionIndex; | |||
reportActionSize.current = sortedVisibleReportActions.length; | |||
hasNewestReportActionRef.current = hasNewestReportAction; |
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are updated in different parts of the lifecycle:
hasNewestReportAction
changes during renderinghasNewestReportActionRef
changes 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that also makes sense to me now.
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.
@aldo-expensify @dukenv0307 I updated to update the ref whenever re-rendering.
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 both
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.
@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 Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.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
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