Skip to content

[$500] Distance - Duplicate waypoint error message is not dimissed after closing distance editor #34999

Closed

Description

@lanitochka17

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: 1.4.30-0
Reproducible in staging?: Y
Reproducible in production?: Y
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: Applause - Internal Team
Slack conversation:

Action Performed:

Precondition: App location access is disabled

  1. Go to workspace chat
  2. Create a distance request with A-B-A address
  3. Navigate to request details page
  4. Click Distance
  5. Drag the waypoint so that it becomes A-A-B
  6. Save the request
  7. Exit the distance editor
  8. Refresh the page
  9. Click Distance

Expected Result:

The duplicate waypoint error message is dismissed

Actual Result:

The duplicate waypoint error message is not dismissed

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6352460_1706039016934.20240123_235006.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~018929236a56deb238
  • Upwork Job ID: 1749887372530053120
  • Last Price Increase: 2024-01-30
  • Automatic offers:
    • alitoshmatov | Reviewer | 28142961
    • tienifr | Contributor | 28142962
Issue OwnerCurrent Issue Owner: @JmillsExpensify

Activity

  1. added
    External
    Daily
    Bug
    on Jan 23, 2024
  2. changed the title [-]Distance - Duplicate waypoint error message is not dimissed after closing distance editor[/-] [+][$500] Distance - Duplicate waypoint error message is not dimissed after closing distance editor[/+] on Jan 23, 2024
  3. melvin-bot commented on Jan 23, 2024

    @melvin-bot
  4. melvin-bot commented on Jan 23, 2024

    @melvin-bot

    Triggered auto assignment to @JmillsExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

  5. added
    Help Wanted
    on Jan 23, 2024
  6. melvin-bot commented on Jan 23, 2024

    @melvin-bot

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

  7. lanitochka17 commented on Jan 23, 2024

    @lanitochka17
    Author

    We think that this bug might be related to #wave6.
    CC @greg-schroeder

  8. paultsimura commented on Jan 23, 2024

    @paultsimura
    Contributor

    Proposal

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

    The "Duplicate waypoint" error remains between the "edit distance" page refreshes.

    What is the root cause of that problem?

    For the distance request, we use a hook that restores the transaction to the original one if it was not saved:

    return () => {
    // If the user cancels out of the modal without without saving changes, then the original transaction
    // needs to be restored from the backup so that all changes are removed.
    if (transactionWasSaved.current) {
    return;
    }
    TransactionEdit.restoreOriginalTransactionFromBackup(transaction.transactionID);
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);

    However, in this issue's scenario, we save the transaction (transactionWasSaved.current becomes true), but the changes are not persisted due to the route error. However, we still return early because the condition of transactionWasSaved.current is met, and therefore do not fully restore the transaction to its original state.

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

    We should add an extra check – early return only if the transaction was saved without a route error:

            return () => {
                // If the user cancels out of the modal without saving changes, then the original transaction
                // needs to be restored from the backup so that all changes are removed.
                if (transactionWasSaved.current && !hasRouteError) {
                    return;
                }
                TransactionEdit.restoreOriginalTransactionFromBackup(transaction.transactionID);
            };

    What alternative solutions did you explore? (Optional)

  9. JordanLevy19 commented on Jan 23, 2024

    @JordanLevy19

    Proposal

    Please re-state the problem that we are trying to solve in this issue.
    The error message regarding non-unique waypoints in a distance request feature persists even after a user refreshes the page. This indicates that the error state is not being reset as expected during a page reload.

    What is the root cause of that problem?
    The root cause of the error message persisting after a page refresh is perhaps due to the hasError state in the DistanceRequest component not being reset correctly. The state is initially set to false, but the code only explicitly resets it in a specific useEffect cleanup function tied to the transaction and transactionID dependencies. If this cleanup function doesn't trigger correctly on a page refresh - either because the component isn't unmounting/remounting properly, or the dependencies don't change as expected - then the hasError state remains true, causing the error message to persist. Additionally, the submitWaypoints function sets this error state under certain conditions, but without a corresponding reset mechanism that activates on page refresh, the error state is not cleared.

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

    Ensure hasError Resets on Page Refresh:
    Modify the useEffect for transaction and transactionID to explicitly reset hasError not only when the component unmounts but also when it remounts, which typically happens on a page refresh. This can involve adding a condition to check if waypoints or relevant conditions have been reinitialized and reset hasError accordingly.

    Review and Update submitWaypoints Logic:
    Implement a mechanism in submitWaypoints to reset hasError when the conditions that initially set it to true no longer apply. This could involve adding a state update at the start of this function to reset the error state, or incorporating additional checks to ensure the state aligns with the current conditions.

    Improve Waypoints Update Logic:
    In updateWaypoints, add logic to reassess the error state whenever waypoints are successfully updated. This ensures that if the error condition related to waypoints is resolved, hasError is reset to false.

    What alternative solutions did you explore? (Optional)

  10. samilabud commented on Jan 23, 2024

    @samilabud
    Contributor

    Proposal

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

    Distance - waypoint error message is not dimissed after closing distance editor

    What is the root cause of that problem?

    We are using Onyx to store and persist errors inside the transaction object:

    errorFields?: OnyxCommon.ErrorFields<'route'>;

    Because of this when we got an error we going to keep it at least we save the waypoints again.

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

    We should clean the transaction errors when unmount the Distance request component inside the next line:

    The code result should be:

    .
    .
    .
      return () => {
                // If there are error cached in onyx
                if (hasRouteError) {
                    TransactionEdit.cleanTransactionErrors(transaction);
                }
    .
    .
    .
    

    And the cleanTransactionErrors could be (inside of https://github.com/Expensify/App/blob/main/src/libs/actions/TransactionEdit.ts):

    function cleanTransactionErrors(transaction: OnyxEntry<Transaction>) {
        if (!transaction) {
            return;
        }
        const newTransaction = {
            ...transaction,
            errorFields: {
                route: {},
            },
        };
        Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, newTransaction);
    }
    

    Result:

    Distance.request.error.test.mp4
  11. Krishna2323 commented on Jan 24, 2024

    @Krishna2323
    Contributor

    Proposal

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

    Distance - Duplicate waypoint error message is not dimissed after closing distance editor

    What is the root cause of that problem?

    We save the waypoints even if we have duplicates & thats why its been stored in ONYX and it persists after refresh.

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

    We should not save the waypoint if we have duplicates. We need to return from here:

    if (_.size(validatedWaypoints) < 2 || hasRouteError || isLoadingRoute || (isLoading && !isOffline)) {

    To validate we can add an extra check like, (_.keys(waypoints).length > 2 && _.size(validatedWaypoints) !== _.keys(waypoints).length) to check if the all waypoints are valid.

    We already have done it inside IOURequestStepDistance:

    if (_.size(validatedWaypoints) < 2 || (_.keys(waypoints).length > 2 && _.size(validatedWaypoints) !== _.keys(waypoints).length) || hasRouteError || isLoadingRoute || isLoading) {
    setHasError(true);
    return;

    Result

  12. 28 remaining items

  13. melvin-bot commented on Feb 5, 2024

    @melvin-bot

    📣 @tienifr 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

    Offer link
    Upwork job
    Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
    Keep in mind: Code of Conduct | Contributing 📖

  14. melvin-bot commented on Feb 6, 2024

    @melvin-bot

    @JmillsExpensify @tgolen @alitoshmatov @tienifr this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

  15. added
    Reviewing
    Weekly
    and removed
    Daily
    on Feb 6, 2024
  16. tienifr commented on Mar 1, 2024

    @tienifr
    Contributor

    @JmillsExpensify PR hit production. Melvin is malfunctioning. Please add HOLD for payment label.

  17. tienifr commented on Mar 18, 2024

    @tienifr
    Contributor

    @JmillsExpensify PR hit production. Melvin is malfunctioning. Please add HOLD for payment label.

    @JmillsExpensify Would you mind helping with payment here? Thanks

  18. alitoshmatov commented on Mar 26, 2024

    @alitoshmatov
    Contributor
  19. JmillsExpensify commented on Mar 29, 2024

    @JmillsExpensify
    Contributor

    If you need something urgent please please reach out to me in Slack in our open source community or directly 1:1. Sorry for the delay!

  20. JmillsExpensify commented on Mar 29, 2024

    @JmillsExpensify
    Contributor

    Payment summary:

    Also @alitoshmatov I don't believe I've seen a BZ checklist. Can you please complete one? Thank you.

  21. JmillsExpensify commented on Mar 29, 2024

    @JmillsExpensify
    Contributor

    All contributors have been paid out though please @alitoshmatov help with the BZ checklist before we can close this on out!

  22. JmillsExpensify commented on Apr 1, 2024

    @JmillsExpensify
    Contributor

    @alitoshmatov bump on the BZ checklist.

  23. alitoshmatov commented on Apr 1, 2024

    @alitoshmatov
    Contributor
    • The PR that introduced the bug has been identified. Link to the PR: feat: enable next button #29125
    • 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/29125/files#r1546740052
    • A discussion in #expensify-bugs 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: No need
    • Determine if we should create a regression test for this bug. No need

    cc: @JmillsExpensify

  24. JmillsExpensify commented on Apr 1, 2024

    @JmillsExpensify
    Contributor

    Great thanks so much! Given no regression test is required, I'll close the issue.

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

Metadata

Metadata

Labels

BugExternalReviewingWeekly

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions