Skip to content

[$250] Report opens with expense rows highlighted and page scrolled down #68685

Closed

Description

@m-natarajan

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number:
Reproducible in staging?: Needs Reproduction
Reproducible in production?: Needs Reproduction
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @shawnborton
Slack conversation (hyperlinked to channel name): #Expensify Bugs

Action Performed:

  1. Navigate to Reports
  2. Open a report that contains more than 10 card expenses
  3. Observe that the expense rows are highlighted
  4. Notice that the page loads scrolled down instead of starting at the top.

Expected Result:

No expense rows should be highlighted by default when opening a report.
The report view should always start scrolled to the very top, regardless of how many expenses are in the report.

Actual Result:

Expense rows are highlighted upon opening. For reports with >10 card expenses, the page is not at the top but is scrolled down by default.

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop
Platforms Tested: On which of our officially supported platforms was this issue tested:
  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

The video for the issue is in OP

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021957565230943425423
  • Upwork Job ID: 1957565230943425423
  • Last Price Increase: 2025-08-18
Issue OwnerCurrent Issue Owner: @

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Aug 18, 2025
  2. melvin-bot commented on Aug 18, 2025

    @melvin-bot

    Triggered auto assignment to @lschurr (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. MelvinBot commented on Aug 18, 2025

    @MelvinBot
    Contributor

    This has been labelled "Needs Reproduction". Follow the steps here: https://stackoverflowteams.com/c/expensify/questions/16989

  4. truph01 commented on Aug 18, 2025

    @truph01
    Contributor

    I can reproduce this bug by following the test step in OP:

    Screen.Recording.2025-08-19.at.02.50.37.mov

    I can take over this issue as C+ based on message.

  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    and removed on Aug 18, 2025
  6. changed the title [-]Report opens with expense rows highlighted and page scrolled down[/-] [+][$250] Report opens with expense rows highlighted and page scrolled down[/+] on Aug 18, 2025
  7. melvin-bot commented on Aug 18, 2025

    @melvin-bot
  8. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Aug 18, 2025
  9. melvin-bot commented on Aug 18, 2025

    @melvin-bot

    Current assignee @truph01 is eligible for the External assigner, not assigning anyone new.

  10. trjExpensify commented on Aug 18, 2025

    @trjExpensify
    Contributor

    Thanks, @truph01. Assigned you for C+ duties.

  11. mkzie2 commented on Aug 19, 2025

    @mkzie2
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Expense rows are highlighted upon opening. For reports with >10 card expenses, the page is not at the top but is scrolled down by default.

    What is the root cause of that problem?

    The backend can return some transactions of the expense report in OpenApp API. When it happens, useNewTransactions hook returns the remaining list of transactions of the expense report after the OpenReport API is complete

    const newTransactions = useNewTransactions(reportMetadata?.hasOnceLoadedReportActions, transactions);

    function useNewTransactions(hasOnceLoadedReportActions: boolean | undefined, transactions: Transaction[] | undefined) {
    // If we haven't loaded report yet we set previous transactions to undefined.
    const prevTransactions = usePrevious(hasOnceLoadedReportActions ? transactions : undefined);
    // We need to skip the first transactions change, to avoid highlighting transactions on the first load.
    const skipFirstTransactionsChange = useRef(!hasOnceLoadedReportActions);
    const newTransactions = useMemo(() => {
    if (transactions === undefined || prevTransactions === undefined || transactions.length <= prevTransactions.length) {
    return CONST.EMPTY_ARRAY as unknown as Transaction[];
    }
    if (skipFirstTransactionsChange.current) {
    skipFirstTransactionsChange.current = false;
    return CONST.EMPTY_ARRAY as unknown as Transaction[];
    }
    return transactions.filter((transaction) => !prevTransactions?.some((prevTransaction) => prevTransaction.transactionID === transaction.transactionID));
    // Depending only on transactions is enough because prevTransactions is a helper object.
    // eslint-disable-next-line react-compiler/react-compiler
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [transactions]);

    Then the expense is highlighted, and the page scrolls down to the highlighted expense here.

    const scrollToNewTransaction = useCallback(
    (pageY: number) => {
    wrapperViewRef.current?.measureInWindow((x, y, w, height) => {
    // If the new transaction is already visible, we don't need to scroll to it
    if (pageY > 0 && pageY < height) {
    return;
    }

    What changes do you think we should make in order to solve the problem?

    We should consider hasOnceLoadedReportActions param as true if it's not the first time the OpenReport is called. That means the previous value of reportMetadata?.hasOnceLoadedReportActions is true

    const prevHasOnceLoadedReportActions = usePrevious(reportMetadata?.hasOnceLoadedReportActions)
    const newTransactions = useNewTransactions(reportMetadata?.hasOnceLoadedReportActions && prevHasOnceLoadedReportActions, transactions);
    

    const newTransactions = useNewTransactions(reportMetadata?.hasOnceLoadedReportActions, transactions);

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    NA

    What alternative solutions did you explore? (Optional)

    We can only consider a transaction to be a new transaction if it's just created by checking the inserted time

    const isNewTransaction = (transaction: Transaction, prevTransactions: Transaction[]) => {
    const currentTime = DateUtils.getDBTime();
    const isJustCreated = new Date(currentTime).getTime() - new Date(transaction.inserted ?? '').getTime() < 1000;
    return isJustCreated && !prevTransactions.some((prevTransaction) => prevTransaction.transactionID === transaction.transactionID);
    }
    return transactions.filter((transaction) => isNewTransaction(transaction, prevTransactions));
    

    function useNewTransactions(hasOnceLoadedReportActions: boolean | undefined, transactions: Transaction[] | undefined) {
    // If we haven't loaded report yet we set previous transactions to undefined.
    const prevTransactions = usePrevious(hasOnceLoadedReportActions ? transactions : undefined);
    // We need to skip the first transactions change, to avoid highlighting transactions on the first load.
    const skipFirstTransactionsChange = useRef(!hasOnceLoadedReportActions);
    const newTransactions = useMemo(() => {
    if (transactions === undefined || prevTransactions === undefined || transactions.length <= prevTransactions.length) {
    return CONST.EMPTY_ARRAY as unknown as Transaction[];
    }
    if (skipFirstTransactionsChange.current) {
    skipFirstTransactionsChange.current = false;
    return CONST.EMPTY_ARRAY as unknown as Transaction[];
    }
    return transactions.filter((transaction) => !prevTransactions?.some((prevTransaction) => prevTransaction.transactionID === transaction.transactionID));
    // Depending only on transactions is enough because prevTransactions is a helper object.
    // eslint-disable-next-line react-compiler/react-compiler
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [transactions]);

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  12. Pujan92 commented on Aug 19, 2025

    @Pujan92
    Contributor

    We have a similar issue and we can put this on hold until that's #66801 merged.

  13. self-assigned this
    on Aug 19, 2025
  14. shawnborton commented on Aug 19, 2025

    @shawnborton
    Contributor

    Ah yeah, we can probably close this issue in favor of that linked PR.

  15. trjExpensify commented on Aug 19, 2025

    @trjExpensify
    Contributor

    yeah, agreed this is a dupe, let's close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions