Skip to content

[Due for payment 2025-08-01] [$250] mWeb - Expense - Create expense page is shown briefly when adding unreported expense to report #65472

Closed

Description

@jponikarchuk

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: V9.1.76-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/6428613
Email or phone of affected tester (no customers): Slottwo1 249553g44@gmail.com
Issue reported by: Applause Internal Team
Device used: Redminote 10s android 13
App Component: Money Requests

Action Performed:

  1. Go to https://staging.new.expensify.com/home
  2. Open self dm
  3. Create a track manual expense
  4. Open workpace chat
  5. Create a report
  6. Open drop down and select add Unreported expense
  7. Select the expense
  8. Tap add to report

Expected Result:

On adding unreported expense to report briefly create expense page must not be shown.

Actual Result:

On adding unreported expense to report briefly create expense page is shown.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021940997829224157860
  • Upwork Job ID: 1940997829224157860
  • Last Price Increase: 2025-07-04
  • Automatic offers:
    • daledah | Contributor | 107966673
Issue OwnerCurrent Issue Owner: @kadiealexander

Activity

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

    @melvin-bot

    Triggered auto assignment to @kadiealexander (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. daledah commented on Jul 4, 2025

    @daledah
    Contributor

    Proposal

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

    On adding unreported expense to report briefly create expense page is shown.

    What is the root cause of that problem?

    We call dismissModal and changeTransactionsReport at the same time

    Navigation.dismissModal();
    changeTransactionsReport([...selectedIds], report?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID, policy);

    So the optimistic data is merged before the screen finishes navigating and "No unreported expenses" is shown briefly

    if (thereIsNoUnreportedTransaction) {
    return (
    <ScreenWrapper
    shouldEnableKeyboardAvoidingView={false}
    includeSafeAreaPaddingBottom
    shouldShowOfflineIndicator={false}
    shouldEnablePickerAvoiding={false}
    testID={NewChatSelectorPage.displayName}
    focusTrapSettings={{active: false}}
    >
    <HeaderWithBackButton
    title={translate('iou.addUnreportedExpense')}
    onBackButtonPress={Navigation.goBack}
    />
    <EmptyStateComponent
    cardStyles={[styles.appBG]}
    cardContentStyles={[styles.pt5, styles.pb0]}
    headerMediaType={CONST.EMPTY_STATE_MEDIA.ANIMATION}
    headerMedia={LottieAnimations.GenericEmptyState}
    title={translate('iou.emptyStateUnreportedExpenseTitle')}
    subtitle={translate('iou.emptyStateUnreportedExpenseSubtitle')}
    headerStyles={[styles.emptyStateMoneyRequestReport]}
    lottieWebViewStyles={styles.emptyStateFolderWebStyles}
    headerContentStyles={styles.emptyStateFolderWebStyles}
    buttons={[
    {
    buttonText: translate('iou.createExpense'),
    buttonAction: () => {
    if (report && report.policyID && shouldRestrictUserBillableActions(report.policyID)) {
    Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(report.policyID));
    return;
    }
    interceptAnonymousUser(() => {
    startMoneyRequest(CONST.IOU.TYPE.SUBMIT, reportID, undefined, false, backToReport);
    });
    },
    success: true,
    },
    ]}
    />
    </ScreenWrapper>
    );
    }

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

    We should delay the changeTransactionsReport here

    Navigation.dismissModal();
    changeTransactionsReport([...selectedIds], report?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID, policy);

    InteractionManager.runAfterInteractions(() => changeTransactionsReport([...selectedIds], report?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID, policy));
    Screen.Recording.2025-07-04.at.11.33.43.mov

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

    None, UI issue.

    What alternative solutions did you explore? (Optional)

    We can call changeTransactionsReport on page unmount, but this approach will make more delays. Implement like below

    const [isTransactionAdded, setIsTransactionAdded] = useState(false);

    onConfirm={() => {
    if (selectedIds.size === 0) {
    setErrorMessage(translate('iou.selectUnreportedExpense'));
    return;
    }
    Navigation.dismissModal();
    changeTransactionsReport([...selectedIds], report?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID, policy);
    setErrorMessage('');
    }}

                    onConfirm={() => {
                        if (selectedIds.size === 0) {
                            setErrorMessage(translate('iou.selectUnreportedExpense'));
                            return;
                        }
                        Navigation.dismissModal();
                        setIsTransactionAdded(true);
                        setErrorMessage('');
                    }}
        useEffect(
            () => () => {
                if (!isTransactionAdded) {
                    return;
                }
                changeTransactionsReport([...selectedIds], report?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID, policy);
            },
            [isTransactionAdded, policy, report?.reportID, selectedIds],
        );

    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.

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jul 4, 2025
  5. melvin-bot commented on Jul 4, 2025

    @melvin-bot
  6. changed the title [-]mWeb - Expense - Create expense page is shown briefly when adding unreported expense to report[/-] [+][$250] mWeb - Expense - Create expense page is shown briefly when adding unreported expense to report[/+] on Jul 4, 2025
  7. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jul 4, 2025
  8. melvin-bot commented on Jul 4, 2025

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @allroundexperts (External)

  9. moved this to Bugs and Follow Up Issues in #expensify-bugson Jul 4, 2025
  10. Shahidullah-Muffakir commented on Jul 4, 2025

    @Shahidullah-Muffakir
    Contributor

    Proposal

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

    When adding unreported expenses to a report, users briefly see the "create expense" page (empty state) before the modal is dismissed.

    What is the root cause of that problem?

    The issue happens because when we call changeTransactionsReport(), the unreported expenses immediately become reported expenses. This makes thereIsNoUnreportedTransaction become true, which triggers the component to re-render and show the empty state with the "create expense" button. This re-render happens before the modal is fully dismissed, causing the brief flash.

    The problem occurs in this sequence:

    1. User clicks "Add to report"
    2. changeTransactionsReport() runs and moves expenses to the report
    3. thereIsNoUnreportedTransaction becomes true because no unreported expenses are left
    4. Component re-renders and shows empty state
    5. Modal dismisses, but user already saw the empty state flash

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

    We should add a state flag to track when we are in the process of adding transactions. This will prevent the empty state from showing during the transition period:

    1. Add a new state isAddingTransactions to track when we're processing transactions
        const [isAddingTransactions, setIsAddingTransactions] = useState(false);
    1. Update the thereIsNoUnreportedTransaction condition to also check this flag
      const thereIsNoUnreportedTransaction = !((sections.at(0)?.data.length ?? 0) > 0);

      as:
        const thereIsNoUnreportedTransaction = !((sections.at(0)?.data.length ?? 0) > 0) && !isAddingTransactions;
    1. Set the flag to true before processing transactions
      onConfirm={() => {
      if (selectedIds.size === 0) {
      setErrorMessage(translate('iou.selectUnreportedExpense'));
      return;
      }
      Navigation.dismissModal();
      changeTransactionsReport([...selectedIds], report?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID, policy);
      setErrorMessage('');
      }}

      as:
     onConfirm={() => {
         if (selectedIds.size === 0) {
             setErrorMessage(translate('iou.selectUnreportedExpense'));
             return;
         }
    +    setIsAddingTransactions(true);
         Navigation.dismissModal();
         changeTransactionsReport([...selectedIds], report?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID, policy);
         setErrorMessage('');
     }}

    Now even when all unreported expenses are moved to reports, the empty state won't show during the transition because isAddingTransactions will be true.

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

    I don't think we need test for this, however if we want we can add a test to not show the EmptyStateComponent if the isAddingTransactions is true.

    What alternative solutions did you explore? (Optional)

    Using InteractionManager.runAfterInteractions(): This approach delays the changeTransactionsReport() call until after the modal dismisses. However, this creates another bug because:

    • The expenses appears in the next report screen with a delay
    Video for main solution
    Screen.Recording.2025-07-04.at.11.34.23.AM.mov
  11. dmkt9 commented on Jul 5, 2025

    @dmkt9
    Contributor

    Proposal

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

    Create expense page is shown briefly when adding unreported expense to report

    What is the root cause of that problem?

    • Because after confirmation, the modal and change transaction are processed simultaneously:
      Navigation.dismissModal();
      changeTransactionsReport([...selectedIds], report?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID, policy);
    • Because the change transaction will change optimistic data first, it will re-render the list with an empty list. And we will see EmptyStateComponent before the modal is dismissed.

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

    We should ensure that the data immediately before and after confirmation remains unchanged. This guarantees the list continues to render smoothly and prevents a delay where the new transaction is only added after the modal has fully disappeared

    + const transactionsAfterConfirmRef = useRef<Array<OnyxEntry<Transaction>> | null>(null);
    function getUnreportedTransactions(transactions: OnyxCollection<Transaction>) {
    + transactionsAfterConfirmRef.current = transactions;
    Navigation.dismissModal();
    function getUnreportedTransactions(transactions: OnyxCollection<Transaction>) {
    +    if (transactionsAfterConfirmRef.current) {
    +        return transactionsAfterConfirmRef.current;
    +    }

    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)

    NA

    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. 19 remaining items

  13. changed the title [-][$250] mWeb - Expense - Create expense page is shown briefly when adding unreported expense to report[/-] [+][Due for payment 2025-08-01] [$250] mWeb - Expense - Create expense page is shown briefly when adding unreported expense to report[/+] on Jul 25, 2025
  14. melvin-bot commented on Jul 25, 2025

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  15. melvin-bot commented on Jul 25, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.85-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-08-01. 🎊

    For reference, here are some details about the assignees on this issue:

  16. melvin-bot commented on Jul 25, 2025

    @melvin-bot

    @allroundexperts @kadiealexander The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  17. allroundexperts commented on Jul 26, 2025

    @allroundexperts
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: https://github.com/Expensify/App/pull/62651/files#r2233257366

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: N/A

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue: https://github.com/Expensify/Expensify/issues/531776

    Regression Test Proposal

    Precondition:

    • Have an account with a workspace and self DM enabled

    Test:

    1. Open self dm
    2. Create a track manual expense
    3. Open workspace chat
    4. Create a report
    5. Open drop down and select add Unreported expense
    6. Select the expense
    7. Tap add to report

    Verify that on adding the unreported expense to a report, the create expense page does not show up briefly.

    Do we agree 👍 or 👎

  18. kadiealexander commented on Aug 1, 2025

    @kadiealexander
    Contributor

    Payments needed:

  19. moved this from Bugs and Follow Up Issues to Done in #expensify-bugson Aug 1, 2025
  20. trjExpensify commented on Jan 5, 2026

    @trjExpensify
    Contributor

    approved $250 for @allroundexperts.

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions