Skip to content

[HOLD for payment 2023-10-02] [$500] Web - Chat - The deleted message reappears when navigating to another chat and returning #27569

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!


Action Performed:

  1. Open any chat
  2. Write a message but do not send it; instead, select all text and delete it
  3. After deleting, press Enter immediately
  4. Switch to a different chat and then return to the original chat
  5. Observe that the deleted message reappears

Expected Result:

The message should be deleted permanently

Actual Result:

The message reappears

Workaround:

Unknown

Platforms:

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

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.70-5

Reproducible in staging?: Yes

Reproducible in production?: Yes

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

Notes/Photos/Videos: Any additional supporting documentation

Bug.mp4
Recording.22.2.mp4

Expensify/Expensify Issue URL:

Issue reported by: @usmantariq96

Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1694585707620149

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01c0cd42dfc8371fd8
  • Upwork Job ID: 1702812597778710528
  • Last Price Increase: 2023-09-15
  • Automatic offers:
    • bernhardoj | Contributor | 26730775

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 15, 2023
  2. changed the title [-]Web - Chat - The deleted message reappears when navigating to another chat and returning[/-] [+][$500] Web - Chat - The deleted message reappears when navigating to another chat and returning[/+] on Sep 15, 2023
  3. melvin-bot commented on Sep 15, 2023

    @melvin-bot

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

  4. melvin-bot commented on Sep 15, 2023

    @melvin-bot
  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Sep 15, 2023
  6. melvin-bot commented on Sep 15, 2023

    @melvin-bot

    Bug0 Triage Checklist (Main S/O)

    • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
    • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
      • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
    • This bug is reproducible using the reproduction steps in the OP. S/O
      • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
      • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
    • This issue is filled out as thoroughly and clearly as possible
      • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
    • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
  7. melvin-bot commented on Sep 15, 2023

    @melvin-bot

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

  8. melvin-bot commented on Sep 15, 2023

    @melvin-bot

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

  9. DylanDylann commented on Sep 15, 2023

    @DylanDylann
    Contributor

    Proposal

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

    • Web - Chat - The deleted message reappears when navigating to another chat and returning.

    What is the root cause of that problem?

    • Currently, clicking on send button or press ENTER will call submitForm function:
      const submitForm = useCallback(
      (e) => {
      if (e) {
      e.preventDefault();
      }
      // Since we're submitting the form here which should clear the composer
      // We don't really care about saving the draft the user was typing
      // We need to make sure an empty draft gets saved instead
      debouncedSaveReportComment.cancel();
      const newComment = composerRef.current.prepareCommentAndResetComposer();
      if (!newComment) {
      return;
      }
      onSubmit(newComment);
      },
      [onSubmit],
      );

      const prepareCommentAndResetComposer = useCallback(() => {
      const trimmedComment = commentRef.current.trim();
      const commentLength = ReportUtils.getCommentLength(trimmedComment);
      // Don't submit empty comments or comments that exceed the character limit
      if (!commentLength || commentLength > CONST.MAX_COMMENT_LENGTH) {
      return '';
      }
    • When deleting all text input (for example "abcdef") and clicking on send button or pressing on ENTER:
    1. Firstly, debouncedSaveReportComment.cancel(); called to ignore the before saveReportComment action - in this case is saving the report comment as an empty string - Report.saveReportComment(reportID, ''). So after this step, the reportComment is still "abcdef" text
    2. After that, composerRef.current.prepareCommentAndResetComposer() is called but it will check if the current comment is empty or not, if true, does not run the remaining logic.
    3. So the report comment is still saved as "abcdef", that lead to the bug

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

    • We can make sure the ``updateComment(' ')``` is called regardless the comment length is greater than 0 or not like below:
        const prepareCommentAndResetComposer = useCallback(() => {
            const trimmedComment = commentRef.current.trim();
            const commentLength = ReportUtils.getCommentLength(trimmedComment);
            updateComment('');
            // Don't submit empty comments or comments that exceed the character limit
            if (!commentLength || commentLength > CONST.MAX_COMMENT_LENGTH) {
                return '';
            }
    
    • Also in the PR detail, we need to ignore the updateComment(' ') in case exceeding the maximum character

    What alternative solutions did you explore? (Optional)

    Result

    Screencast.from.14-09-2023.14.43.07.webm
  10. bernhardoj commented on Sep 16, 2023

    @bernhardoj
    Contributor

    Proposal

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

    The deleted composer message shows again if pressing enter after deleting the whole message/text.

    What is the root cause of that problem?

    The initial text that is shown on composer comes from the report comment draft onyx (reportDraftComment_). Every time we update the text, we save the text as a draft, but we are debouncing it so the save doesn't get called too much for each character.

    if (shouldDebounceSaveComment) {
    debouncedSaveReportComment(reportID, newComment);

    When we press enter, it will call submitForm which will cancel any ongoing debounce.

    // Since we're submitting the form here which should clear the composer
    // We don't really care about saving the draft the user was typing
    // We need to make sure an empty draft gets saved instead
    debouncedSaveReportComment.cancel();

    So, if we delete the whole text and then immediately press enter, the request to save the draft with an empty string is canceled, thus the onyx still holds the old value. That's why when we revisit the chat, we will see the old value shows.

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

    Cancel the debounce only if the composer is not empty.

    details:
    We have 2 options,

    1. In this code, move down the debounce cancel below the if.
      // Since we're submitting the form here which should clear the composer
      // We don't really care about saving the draft the user was typing
      // We need to make sure an empty draft gets saved instead
      debouncedSaveReportComment.cancel();
      const newComment = composerRef.current.prepareCommentAndResetComposer();
      if (!newComment) {
      return;
      }
    if (!newComment) {
        return;
    }
    debouncedSaveReportComment.cancel();
    
    1. Move the debounce cancel from submitForm to prepareCommentAndResetComposer and call it right above updateComment('')
      if (!commentLength || commentLength > CONST.MAX_COMMENT_LENGTH) {
      return '';
      }
      updateComment('');
  11. 32 remaining items

  12. tjferriss commented on Oct 2, 2023

    @tjferriss
    Contributor

    @bernhardoj payment has been sent via Upworks.

    @usmantariq96 I just sent you an offer via Upworks for the reporting bonus.

  13. usmantariq96 commented on Oct 3, 2023

    @usmantariq96

    @tjferriss I haven't received any offer yet.

  14. tjferriss commented on Oct 3, 2023

    @tjferriss
    Contributor

    I'm sorry, I must have selected the wrong person. Can you please apply to the posting here: https://www.upwork.com/jobs/~01c0cd42dfc8371fd8

  15. JmillsExpensify commented on Oct 5, 2023

    @JmillsExpensify
    Contributor

    $750 payment approved for @mananjadhav based on BZ summary

  16. tjferriss commented on Oct 5, 2023

    @tjferriss
    Contributor

    @usmantariq96 can you please apply to the job so we can get you paid out?

  17. usmantariq96 commented on Oct 6, 2023

    @usmantariq96

    @tjferriss applied
    Thanks

  18. tjferriss commented on Oct 6, 2023

    @tjferriss
    Contributor

    Offer sent

  19. usmantariq96 commented on Oct 7, 2023

    @usmantariq96

    Offer accepted
    Thanks

  20. cristipaval commented on Oct 9, 2023

    @cristipaval
    Contributor

    What's the payment status here? Can we close the issue?

  21. tjferriss commented on Oct 11, 2023

    @tjferriss
    Contributor

    The payment has been sent to @usmantariq96 so we can close it now.

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

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions