Skip to content

fix: autoscroll when receiving a payment#57609

Merged
aldo-expensify merged 5 commits into
Expensify:mainfrom
callstack-internal:fix/autoscroll-when-receiving-payment
Mar 20, 2025
Merged

fix: autoscroll when receiving a payment#57609
aldo-expensify merged 5 commits into
Expensify:mainfrom
callstack-internal:fix/autoscroll-when-receiving-payment

Conversation

@TMisiukiewicz
Copy link
Copy Markdown
Contributor

Explanation of Change

Transactions had initial value set to empty array, which was used each time user was going back to the report preview. Based on the amount of the transactions with receipts, if there are none, the ReportActionItemImages was not rendered. After transactions were loaded, it appeared in the report preview, but the positioning of the scroll remained the same. With removing the initial value, we persist the transactions and prevent them to be cleared when going back to the screen.

Fixed Issues

$ #57287
PROPOSAL:

Tests

  1. Open two separate windows with the app with two different accounts (e.g. web and mobile).
  2. Open conversation with user B.
  3. Send some messages so the chat is scrollable
  4. Without navigating out of the conversation, switch to user B account.
  5. User B, open chat with User A.
  6. Tap on "+" button and select "Pay Someone"
  7. Complete the payment flow and submit it to chat.
  8. Switch to user A account again.
  9. Verify the expense appeared in chat and the chat is scrolled to the bottom
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."
Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • 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 added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
android-web.mov
iOS: Native
ios.mov
iOS: mWeb Safari
ios-web.mov
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov

@TMisiukiewicz TMisiukiewicz requested a review from a team as a code owner February 28, 2025 10:40
@melvin-bot melvin-bot Bot requested review from rayane-d and removed request for a team February 28, 2025 10:40
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Feb 28, 2025

@rayane-d 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]

@rayane-d
Copy link
Copy Markdown
Contributor

rayane-d commented Mar 3, 2025

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • 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 steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
Screen.Recording.2025-03-19.at.5.28.42.PM.mov
Android: mWeb Chrome
Screen.Recording.2025-03-19.at.5.24.48.PM.mov
iOS: Native
Screen.Recording.2025-03-19.at.5.23.06.PM.mov
iOS: mWeb Safari
Screen.Recording.2025-03-19.at.5.20.45.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2025-03-19.at.4.22.19.PM.mov
MacOS: Desktop
Screen.Recording.2025-03-19.at.4.49.26.PM.mov

@rayane-d
Copy link
Copy Markdown
Contributor

rayane-d commented Mar 3, 2025

@TMisiukiewicz I'm still able to reproduce the bug when the two sessions are active:

Screen.Recording.2025-03-03.at.4.02.13.PM.mov

@TMisiukiewicz
Copy link
Copy Markdown
Contributor Author

@rayane-d yeah seems like the issue is more complicated 😨 I was able to narrow down the issue - it's most likely trying to find a transaction in useReportWithTransactionsAndViolations when a report is created, but the transaction is not merged yet. It seems to be closely related to the Pusher and the order of the merged data. I need some more time to investigate it. Will continue working on this tomorrow

@TMisiukiewicz
Copy link
Copy Markdown
Contributor Author

TMisiukiewicz commented Mar 5, 2025

Hmm I did more investigation and not sure how to approach this issue. It's because we already have a report action with report ID of IOU, but the transaction is not yet in the Onyx. So the height of the issue changes dynamically once the transaction is loaded and placeholder image is displayed. It's kinda different than the originally fixed issue because in this case we don't trigger an additional rerender through window focus. If Pusher update had a transaction update separated from the rest it would work, but I don't think it's proper solution for this issue.

@rayane-d since this is a separate scenario from the originally reported, how about we move forward with the current shape of the PR to not block the fix for that? We could create a separate issue as this would be related only to web and desktop (because you cannot have the app open on mobile without focus on it).

@TMisiukiewicz
Copy link
Copy Markdown
Contributor Author

@rayane-d friendly bump ⬆️

@rayane-d
Copy link
Copy Markdown
Contributor

Sorry for the delay, checking now

@rayane-d
Copy link
Copy Markdown
Contributor

Trying to investigate as well

@rayane-d
Copy link
Copy Markdown
Contributor

@rayane-d since this is a separate scenario from the originally reported, how about we move forward with the current shape of the PR to not block the fix for that? We could create a separate issue as this would be related only to web and desktop (because you cannot have the app open on mobile without focus on it).

Sounds good to me 👍
Let’s not hold up the work on this case.

@rayane-d
Copy link
Copy Markdown
Contributor

Works well for the originally reported bug

Before After
Screen.Recording.2025-03-19.at.4.38.44.PM.mov
Screen.Recording.2025-03-19.at.4.49.26.PM.mov

@rayane-d
Copy link
Copy Markdown
Contributor

We could create a separate issue as this would be related only to web and desktop (because you cannot have the app open on mobile without focus on it).

Reported here: https://expensify.slack.com/archives/C049HHMV9SM/p1742400602202699

Copy link
Copy Markdown
Contributor

@rayane-d rayane-d left a comment

Choose a reason for hiding this comment

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

LGTM and tests well 👍

@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Mar 19, 2025

We did not find an internal engineer to review this PR, trying to assign a random engineer to #57287 as well as to this PR... Please reach out for help on Slack if no one gets assigned!

@melvin-bot melvin-bot Bot requested a review from aldo-expensify March 19, 2025 16:31
),
});
return [report, transactions, violations];
return [report, transactions ?? [], violations ?? {}];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we memoize the transactions ?? [] and violations ?? {} so the reference to the default values is stable when transactions or violations is undefined/null?

I'm asking for this because we have code using useMemo and passing as a dependency these values. If the [] / {} is recreated on each render, then those useMemo that watch these values won't be able to cache properly.

For example:

const {hasMissingSmartscanFields, areAllRequestsBeingSmartScanned, hasOnlyTransactionsWithPendingRoutes, hasNonReimbursableTransactions} = useMemo(
() => ({
hasMissingSmartscanFields: hasMissingSmartscanFieldsReportUtils(iouReportID),
areAllRequestsBeingSmartScanned: areAllRequestsBeingSmartScannedReportUtils(iouReportID, action),
hasOnlyTransactionsWithPendingRoutes: hasOnlyTransactionsWithPendingRoutesReportUtils(iouReportID),
hasNonReimbursableTransactions: hasNonReimbursableTransactionsReportUtils(iouReportID),
}),
// When transactions get updated these status may have changed, so that is a case where we also want to run this.
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
[transactions, iouReportID, action],
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

an alternative could be to define some constants outside the component for the defaults outside, so they stay as the same instance always:

const DEFAULT_TRANSACTIONS = [];
const DEFAULT_VIOLATIONS = {};

then in the component:

    return [report, transactions ?? DEFAULT_TRANSACTIONS, violations ?? DEFAULT_VIOLATIONS];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks @aldo-expensify , I went with defining the defaults outside, tested it and it works properly 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing

@aldo-expensify aldo-expensify merged commit 8ead17b into Expensify:main Mar 20, 2025
@OSBotify
Copy link
Copy Markdown
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.

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/aldo-expensify in version: 9.1.17-0 🚀

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

@kavimuru
Copy link
Copy Markdown

@cristipaval
Copy link
Copy Markdown
Contributor

This fails on the desktop for me as well. @aldo-expensify please make sure the issue doesn't get closed until we fix the desktop App.

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/cristipaval in version: 9.1.17-1 🚀

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

@TMisiukiewicz
Copy link
Copy Markdown
Contributor Author

Checking 👀

@TMisiukiewicz
Copy link
Copy Markdown
Contributor Author

@kavimuru @cristipaval mind sharing a video? Seems to work fine for me

Screen.Recording.2025-03-25.at.09.58.06.mov

@rayane-d
Copy link
Copy Markdown
Contributor

Failing with #57287 on desktop

https://platform.applause.com/services/links/v1/external/cba2c1eaa8452c5d1c3629934701d945ef55252613d3968fca8497aea375cd4d

I think this is the same issue I reported here. This can be handled in a separate issue

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