Skip to content

Fix - Reports - New expense is not briefly highlighted in the list after expense is submitted#64111

Closed
FitseTLT wants to merge 33 commits into
Expensify:mainfrom
FitseTLT:fix-scroll-to-new-item-search
Closed

Fix - Reports - New expense is not briefly highlighted in the list after expense is submitted#64111
FitseTLT wants to merge 33 commits into
Expensify:mainfrom
FitseTLT:fix-scroll-to-new-item-search

Conversation

@FitseTLT
Copy link
Copy Markdown
Contributor

@FitseTLT FitseTLT commented Jun 12, 2025

Details

Fixed Issues

$ #59449
PROPOSAL: #59449 (comment)

Tests

  1. Go to Reports
  2. Open FAB > Create expense > Manual
  3. Enter amount > Next
  4. Select a user and submit the expense to them
  5. The new expense will be briefly highlighted in Expenses list after the expense is submitted
  • Verify that no errors appear in the JS console

Offline tests

Same as above

QA Steps

Same as above

  • 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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 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 approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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(themeColors.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • 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 form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label 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
2025-06-13.20-28-09.mp4
Android: mWeb Chrome
2025-06-13.20-26-18.mp4
iOS: Native
2025-09-12.23-40-45.mp4
iOS: mWeb Safari
2025-06-13.20-22-49.mp4
MacOS: Chrome / Safari
2025-06-13.01-05-51.mp4
MacOS: Desktop
2025-06-13.20-21-46.mp4

@FitseTLT FitseTLT requested a review from a team as a code owner June 12, 2025 22:07
@melvin-bot melvin-bot Bot requested a review from QichenZhu June 12, 2025 22:07
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Jun 12, 2025

@QichenZhu 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]

// Perform the scrolling action
ref.scrollToIndex(indexOfNewItem);
if (indexOfNewItem === data.length - 1) {
// Scrolling to last item needs a delay to work due to FlatList internal bug.
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.

Is there a chance this is caused by the reason in #61278 (comment)? If so, it's probably not a FlatList bug since we're not using it the recommended way. But if it turns out to be an upstream bug, let's add an issue link so we can remove this workaround once it's fixed upstream.

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.

May be but I don't see the log warning in my console.

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.

The warning was suppressed by #61392.

const onScrollToIndexFailed = () => {};

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.

Yeah exactly @QichenZhu I proved that onScrollToIndexFailed is called in this case. So do you suggest another method that delaying the call?

Copy link
Copy Markdown
Contributor

@QichenZhu QichenZhu Jun 30, 2025

Choose a reason for hiding this comment

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

I don't think we're on the right track to fix this. The codebase has changed a lot since your proposal, so we might need to dig deeper into the root cause and try a different solution. Please let me know if you're still interested. Thanks!

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.

@QichenZhu It is now working for that specific case it was failing (where the item is added to the end of the list) without any workaround delay. Can you check it ?

2025-07-16.17-47-43.mp4

@FitseTLT FitseTLT requested a review from a team as a code owner August 29, 2025 12:04
@QichenZhu
Copy link
Copy Markdown
Contributor

QichenZhu commented Aug 30, 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)
      Expenses created offline are greyed out and not highlighted, but I think that's fine.
  • 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: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • 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 there are no new alerts related to the canBeMissing param for useOnyx
  • 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.
    We already have unit tests, but they can't catch this bug, probably because React render timing behaves differently in real vs. test environments.
  • 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: HybridApp
android-native.webm
Android: mWeb Chrome
android-web.webm
iOS: HybridApp
ios-native.mov
iOS: mWeb Safari
ios-web.mov
MacOS: Chrome / Safari
highlight-old-expenses.mov
MacOS: Desktop
mac-desktop.mov

Copy link
Copy Markdown
Contributor

@QichenZhu QichenZhu left a comment

Choose a reason for hiding this comment

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

@FitseTLT Thanks! This is a nice improvement compared to main branch. Just two things:

  1. Expenses created offline are greyed out and not highlighted. Is this expected?
  2. Screenshot/video for iOS Native is missing.

@melvin-bot melvin-bot Bot requested a review from JS00001 August 30, 2025 09:46
@JS00001
Copy link
Copy Markdown
Contributor

JS00001 commented Sep 10, 2025

@QichenZhu Whats the issue? I'm having trouble following the thread

@QichenZhu
Copy link
Copy Markdown
Contributor

QichenZhu commented Sep 11, 2025

@JS00001, this PR works better than the main branch, except for the three issues listed in my previous comments:

#64111 (review):

  1. Expenses created offline are greyed out and not highlighted. Is this expected?
  2. Screenshot/video for iOS Native is missing.

and #64111 (comment):

The above still applies. I also noticed one more minor issue: both new and old expenses are highlighted.

I think we've hit the limits of this path, and this might be the best outcome we can achieve with it. I'm not sure whether it meets the repo standard and we should proceed and merge it.

@FitseTLT
Copy link
Copy Markdown
Contributor Author

@JS00001, this PR works better than the main branch, except for the three issues listed in my previous comments:

#64111 (review):

  1. Expenses created offline are greyed out and not highlighted. Is this expected?

Yes, it is intentional. This is the code that is preventing it

if (!isFocused || isOffline) {
hasPendingSearchRef.current = true;
return;
}

  1. Screenshot/video for iOS Native is missing.

Added

and #64111 (comment):

The above still applies. I also noticed one more minor issue: both new and old expenses are highlighted.

I think we've hit the limits of this path, and this might be the best outcome we can achieve with it. I'm not sure whether it meets the repo standard and we should proceed and merge it.

Yeah this is a bit out of scope and the first time I tried to solve this problem I tried to use the transaction created prop but unfortunately it only holds the date data, not a timestamp, so unfortunately we cannot precisely tell a transaction is an older one but it is an edge case problem.

@JS00001
Copy link
Copy Markdown
Contributor

JS00001 commented Sep 15, 2025

Expenses created offline are greyed out and not highlighted. Is this expected?

Yes that is expected

Screenshot/video for iOS Native is missing.

Looks like this was added

The above still applies. I also noticed one more minor issue: both new and old expenses are highlighted.

I dont think we should merge this with this issue existing. Let me look into the issue a bit more

@JS00001
Copy link
Copy Markdown
Contributor

JS00001 commented Sep 15, 2025

@FitseTLT Can you explain the issue a bit more and why other expenses are getting highlighted?

@FitseTLT
Copy link
Copy Markdown
Contributor Author

@FitseTLT Can you explain the issue a bit more and why other expenses are getting highlighted?

Yeah @JS00001 This is because hasNewItemsRef is set to true on the creation of new expense. So when the user scrolls down new items will be added and as the hasNewItemsRef will not be reset it will allow this new old expenses to be highlighted. I have updated the solution from using a boolean ref to transactionIDs list ref so that it will hold the new transaction ids and check if the new items added are really new. Result:

2025-09-24.20-04-46.mp4

The other inconsistent bug I am facing is regarding viewOffset here

listRef.current.scrollToIndex({index, animated, viewOffset: variables.contentHeaderHeight});

the documentation says positive value will push it down to the view port but from my testing positive value is pushing it out of view and negative value causing the vice versa. I did change the value to negative on a previous commit but after some time when merging main the switched back. So I have switched to using viewPosition:0 to put the item on top of the view I think this one is more safe and as the bug is internal flatlist one this is the best solution I suggest. Result:

Web:

2025-09-24.21-37-06.mp4

Android:

2025-09-24.21-54-02.mp4

@JS00001
Copy link
Copy Markdown
Contributor

JS00001 commented Sep 25, 2025

I think that looks good, @QichenZhu Could you please re-review?

@QichenZhu
Copy link
Copy Markdown
Contributor

Not trying to nitpick, but I'm still seeing old expenses being highlighted.

I don't think it's related to the highlighting logic. It seems more like an issue with virtual scrolling.

Maybe we should live with it for now and ask an agency for help.

highlight-old-expenses.mov

@JS00001
Copy link
Copy Markdown
Contributor

JS00001 commented Sep 26, 2025

Not trying to nitpick, but I'm still seeing old expenses being highlighted.

I don't think this is a nitpick, and I dont think we should merge this as is. @trjExpensify Any thoughts on this? This PR is supposed to highlight new expenses, but its sometimes highlighting more than one expense, even ones that arent highlighted. I dont think the pros of merging this outweigh the cons

@trjExpensify
Copy link
Copy Markdown
Contributor

Yeah, I agree with you.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 26, 2025

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/components/Search/SearchList/index.tsx 0.00% <0.00%> (ø)
src/components/Search/index.tsx 0.00% <0.00%> (ø)
src/hooks/useSearchHighlightAndScroll.ts 64.06% <66.66%> (-0.74%) ⬇️
... and 24 files with indirect coverage changes

@FitseTLT
Copy link
Copy Markdown
Contributor Author

Not trying to nitpick, but I'm still seeing old expenses being highlighted.

I don't think it's related to the highlighting logic. It seems more like an issue with virtual scrolling.

Maybe we should live with it for now and ask an agency for help.

highlight-old-expenses.mov

This one has nothing to do with useSearchHighlightAndScroll I debugged that we are only setting newSearchResultKey for the new item and even shouldHighlight is only true for the new item useAnimatedHighlightStyle

export default function useAnimatedHighlightStyle({
borderRadius,
shouldHighlight,

I think this is an advanced internal bug of the list component and I don't see how it is related to the scope of this PR.

@JS00001
Copy link
Copy Markdown
Contributor

JS00001 commented Sep 26, 2025

@FitseTLT Is this bug on prod right now?

@FitseTLT
Copy link
Copy Markdown
Contributor Author

@FitseTLT Is this bug on prod right now?

Nope On main the highlighting logic is broken so highlighting doesn't work for the new item too.

@JS00001
Copy link
Copy Markdown
Contributor

JS00001 commented Sep 26, 2025

Yeah I agree the bug could exist but isnt visible. However, I dont think we should be releasing 1 improvement alongside 1 added bug

@FitseTLT
Copy link
Copy Markdown
Contributor Author

Yeah I agree the bug could exist but isnt visible. However, I dont think we should be releasing 1 improvement alongside 1 added bug

I understand your concern. Then, I think we should get someone from expert team for the last bug.

@JS00001
Copy link
Copy Markdown
Contributor

JS00001 commented Oct 10, 2025

@FitseTLT Can you please lay out the bug and the steps to repro it, and what you would need from them, so I can ask for their opinion on it?

@FitseTLT
Copy link
Copy Markdown
Contributor Author

FitseTLT commented Oct 10, 2025

Test Steps:
Precondition: use an account with many expenses already created

  1. Switch to this branch
  2. Go to Reports > Expenses
  3. Apply a filter like currency (ensure there are a lot of results with that filter)
  4. create a new expense with that currency in (4)
  5. when the new item is added to the search and highlighted quickly scroll down

Bug: you will see another old search item from bottom also gets highlighted briefly See. the video in #64111 (comment)

Note: we have debugged that it has nothing to do with the useSearchHighlightAndScroll and we ensured that the hook only sets the proper new item as the newSearchResultKey

return {newSearchResultKey, handleSelectionListScroll, newTransactions};

we suspect some FlatList internal bug is causing it but we are not sure.

2025-10-10.23-33-23.mp4

@JS00001
Copy link
Copy Markdown
Contributor

JS00001 commented Oct 24, 2025

sorry for the holdup, asked here: https://expensify.slack.com/archives/C08CZDJFJ77/p1761316978655769

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.

5 participants