Skip to content

[Due for payment 2025-12-25] [$250] Distance rate - Error shows up after adding and deleting distance rate offline #76027

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: 9.2.63-3
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: Exp https://test-management.browserstack.com/projects/2219752/test-runs/TR-2155/folder/13176744/41237138/1035950356
Email or phone of affected tester (no customers): sdoisdoisdosoisndo@gmail.com
Issue reported by: Applause Internal Team
Device used: Mac 26.1 / Chrome
App Component: Workspace Settings

Action Performed:

Precondition:

  • Distance rates feature is enabled.
  1. Go to staging.new.expensify.com
  2. Go to workspace settings > .Distance rates.
  3. Add two distance rates.
  4. Go offline.
  5. Add third rate.
  6. Delete the second rate (from Step 3).
  7. Delete the third rate (from Step 5).
  8. Go online.
  9. When the second rate reappears, delete it again.
  10. Switch to other tab then back to Distance rates.

Expected Result:

The second rate will be deleted without issue.

Actual Result:

The second rate reappears after returning online.
When trying to delete the second rate again, error shows up.

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/~021996317916684459409
  • Upwork Job ID: 1996317916684459409
  • Last Price Increase: 2025-12-10
Issue OwnerCurrent Issue Owner: @mollfpr

Activity

  1. added
    Daily
    Bug
    on Nov 25, 2025
  2. melvin-bot commented on Nov 25, 2025

    @melvin-bot

    Triggered auto assignment to @muttmuure (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. thelullabyy commented on Nov 25, 2025

    @thelullabyy
    Contributor

    Proposal

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

    The second rate reappears after returning online.
    When trying to delete the second rate again, error shows up.

    What is the root cause of that problem?

    When deleting a rate that was created offline with pendingAction: 'add', the successData doesn't include the deleted rate IDs

    Also deleted rates aren't included in successRates as well

    optimisticRates[rateID] = {
    ...currentRates[rateID],
    enabled: false,
    pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
    };
    failureRates[rateID] = {
    ...currentRates[rateID],
    pendingAction: null,
    errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
    };

    Therefore, when we call delete policy distance rates, it returns error "Invalid ID in custom unit rate"

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

    We should reset success deleted rate from Onyx as well

                successRates[rateID] = null;

    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.

  4. abbasifaizan70 commented on Nov 25, 2025

    @abbasifaizan70
    Contributor

    Proposal

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

    When a user deletes distance rates while offline and then goes back online, the deleted rates reappear. When attempting to delete these rates again, an error occurs. The expected behavior is that the rates should be deleted successfully without errors.

    What is the root cause of that problem?

    The issue occurs in the deletePolicyDistanceRates function in App/src/libs/actions/Policy/DistanceRate.ts. When a distance rate is successfully deleted, the function does not properly remove it from the Onyx store.

    Root Cause Analysis:

    1. Missing deletion in success data: The successData in deletePolicyDistanceRates only includes rates that are NOT being deleted. For deleted rates, the function sets pendingAction: DELETE in the optimistic update, but the success data doesn't set these rates to null to remove them from the store.

    2. Server sync conflict: When the user goes offline, deletes a rate, and then comes back online:

      • The optimistic update marks the rate with pendingAction: DELETE
      • The API call is queued
      • When online, the server sync may bring back the rate (if the deletion hasn't completed yet)
      • The success handler doesn't remove the rate from the store, so it persists even after successful deletion
    3. Comparison with similar code: The deletePolicyTaxes function in App/src/libs/actions/TaxRate.ts correctly handles this by setting deleted taxes to null in the success data (line 377), which removes them from the Onyx store.

    Code Location:

    • App/src/libs/actions/Policy/DistanceRate.ts - deletePolicyDistanceRates function (lines 393-507)

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

    Change 1: Update successRates type to allow null values

    In App/src/libs/actions/Policy/DistanceRate.ts, update the type of successRates to allow null values:

    const successRates: Record<string, Rate | null> = {};

    Why: This allows us to set deleted rates to null in the success data, which removes them from the Onyx store.

    Change 2: Set deleted rates to null in success data

    In the same function, when building successRates, set deleted rates to null:

    for (const rateID of Object.keys(currentRates)) {
        if (rateIDsToDelete.includes(rateID)) {
            optimisticRates[rateID] = {
                ...currentRates[rateID],
                enabled: false,
                pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
            };
            // Set deleted rates to null in success data to remove them from the store
            successRates[rateID] = null;
            failureRates[rateID] = {
                ...currentRates[rateID],
                pendingAction: null,
                errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
            };
        } else {
            optimisticRates[rateID] = currentRates[rateID];
            successRates[rateID] = {
                ...currentRates[rateID],
                pendingAction: null,
            };
        }
    }

    What alternative solutions did you explore? (Optional)

    N/A

  5. bernhardoj commented on Nov 26, 2025

    @bernhardoj
    Contributor

    Proposal

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

    The deleted distance rate re-appears after going online.

    What is the root cause of that problem?

    Whenever we delete a rate, we optimistically set the pending action to delete, but also merge all the current rates when success.

    const currentRates = customUnit.rates;
    const optimisticRates: Record<string, Rate> = {};
    const successRates: Record<string, Rate> = {};
    const failureRates: Record<string, Rate> = {};
    for (const rateID of Object.keys(currentRates)) {
    if (rateIDsToDelete.includes(rateID)) {
    optimisticRates[rateID] = {
    ...currentRates[rateID],
    enabled: false,
    pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
    };
    failureRates[rateID] = {
    ...currentRates[rateID],
    pendingAction: null,
    errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
    };
    } else {
    optimisticRates[rateID] = currentRates[rateID];
    successRates[rateID] = {
    ...currentRates[rateID],
    pendingAction: null,
    };
    }
    }

    So, when we delete the 3rd rate, the 2nd rate will be included on the success data.

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

    We don't need to include the current rates on the success data (and optimisticRates and failureRates) because we use MERGE.

    const optimisticRates: Record<string, Partial<Rate>> = {};
    const failureRates: Record<string, Partial<Rate>> = {};
    
    for (const rateID of rateIDsToDelete) {
        optimisticRates[rateID] = {
            enabled: false,
            pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
        };
        failureRates[rateID] = {
            pendingAction: null,
            errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
        };
    }
  6. melvin-bot commented on Nov 29, 2025

    @melvin-bot

    @muttmuure Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  7. melvin-bot commented on Dec 1, 2025

    @melvin-bot

    @muttmuure Huh... This is 4 days overdue. Who can take care of this?

  8. melvin-bot commented on Dec 3, 2025

    @melvin-bot

    @muttmuure Still overdue 6 days?! Let's take care of this!

  9. added
    External
    on Dec 3, 2025
  10. changed the title [-]Distance rate - Error shows up after adding and deleting distance rate offline[/-] [+][$250] Distance rate - Error shows up after adding and deleting distance rate offline[/+] on Dec 3, 2025
  11. melvin-bot commented on Dec 3, 2025

    @melvin-bot
  12. added
    Help Wanted
    on Dec 3, 2025
  13. 30 remaining items

  14. melvin-bot commented on Dec 25, 2025

    @melvin-bot

    Issue is ready for payment but no BZ is assigned. @lydiabarclay you are the lucky winner! Please verify the payment summary looks correct and complete the checklist. Thanks!

  15. mollfpr commented on Dec 29, 2025

    @mollfpr
    Contributor

    Waiting for payment! cc @lydiabarclay

    @DylanDylann do we need the BZ checklist here?

  16. DylanDylann commented on Dec 29, 2025

    @DylanDylann
    Contributor

    BugZero Checklist:

    Regression Test Proposal

    Test:

    Precondition: have a workspace with a distance rate enabled

    1. Open the distance rate list page
    2. Create at least 2 distance rates
    3. Go offline
    4. Delete one of the rates
    5. Delete another rate
    6. Go online
    7. Verify the deleted rate won't reappear after a few seconds

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-c6e5-a10a-b21a-c8b7ba353644
  17. melvin-bot commented on Jan 1, 2026

    @melvin-bot

    @mollfpr Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  18. mollfpr commented on Jan 5, 2026

    @mollfpr
    Contributor

    Waiting for payment.

  19. lydiabarclay commented on Jan 6, 2026

    @lydiabarclay
    Contributor

    Payment Summary

    Contributor: @bernhardoj due $250 via NewDot
    Contributor+: @DylanDylann due $250 via NewDot

    ✅ Regression test filed

  20. bernhardoj commented on Jan 6, 2026

    @bernhardoj
    Contributor

    Requested in ND.

  21. garrettmknight commented on Jan 14, 2026

    @garrettmknight
    Contributor

    $250 approved for @bernhardoj

  22. JmillsExpensify commented on Jan 20, 2026

    @JmillsExpensify
    Contributor

    $250 approved for @DylanDylann

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

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions