Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOLD for payment 2023-05-25] [$1000] Chat - Comment disappears when edited in _* text _* format #17785

Closed
6 tasks done
kbecciv opened this issue Apr 21, 2023 · 49 comments
Closed
6 tasks done
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review

Comments

@kbecciv
Copy link

kbecciv commented Apr 21, 2023

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. Go to URL https://staging.new.expensify.com/
  2. Login with any account
  3. Go to any chat
  4. Send any text
  5. Edit this text as *text*
  6. Edit ones more as _*text*_
  7. Edit again as _*text_*

Expected Result:

Comment NOT disappears

Actual Result:

Comment disappears

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.3.1

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

Bug6026844_Recording__4237.mp4

Expensify/Expensify Issue URL:

Issue reported by: Applause - Internal Team

Slack conversation:

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01fbc70abb602fff25
  • Upwork Job ID: 1651574084753051648
  • Last Price Increase: 2023-04-27
@kbecciv kbecciv added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Apr 21, 2023
@MelvinBot
Copy link

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

@MelvinBot
Copy link

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

@kbecciv kbecciv changed the title Web - Chat - Comment disappears when edited in _* text _* format Chat - Comment disappears when edited in _* text _* format Apr 21, 2023
@NicMendonca
Copy link
Contributor

@kbecciv just a heads up, when I refresh, the comment comes back -- does that happen for you as well? Or deletes permanently?

@melvin-bot melvin-bot bot added the Overdue label Apr 24, 2023
@NicMendonca
Copy link
Contributor

bump @kbecciv

@melvin-bot melvin-bot bot removed the Overdue label Apr 24, 2023
@kbecciv
Copy link
Author

kbecciv commented Apr 24, 2023

@NicMendonca Let me double check with current build, will update you shortly.

@kbecciv
Copy link
Author

kbecciv commented Apr 24, 2023

@NicMendonca Confirmed, the comment comes back after refresh.

Recording.2574.mp4

@melvin-bot melvin-bot bot added the Overdue label Apr 27, 2023
@NicMendonca
Copy link
Contributor

Okay got it! Super weird.

@melvin-bot melvin-bot bot removed the Overdue label Apr 27, 2023
@NicMendonca NicMendonca added the External Added to denote the issue can be worked on by a contributor label Apr 27, 2023
@melvin-bot melvin-bot bot changed the title Chat - Comment disappears when edited in _* text _* format [$1000] Chat - Comment disappears when edited in _* text _* format Apr 27, 2023
@MelvinBot
Copy link

Job added to Upwork: https://www.upwork.com/jobs/~01fbc70abb602fff25

@MelvinBot
Copy link

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

@MelvinBot
Copy link

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 27, 2023
@MelvinBot
Copy link

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

@deetergp
Copy link
Contributor

I do think this can be worked in by contributors. I suspect it's very similar to #15302.

@kbecciv I took the liberty of editing your description, wrapping your example text in backticks so it shows as monospace code and isn't parsed by Github's Markdown parsers.

@alitoshmatov
Copy link
Contributor

When edited with _*text_* the backend is pushing empty text message for the update:
Screenshot 2023-04-27 at 9 21 01 PM
Screenshot 2023-04-27 at 9 18 52 PM

Oddly enough, if you add a comment with _*text_* it is pushing correct data:
Screenshot 2023-04-27 at 9 22 19 PM
Screenshot 2023-04-27 at 9 22 47 PM

@eh2077
Copy link
Contributor

eh2077 commented Apr 28, 2023

Proposal

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

Comment disappears when edited in _* text _*.

What is the root cause of that problem?

To dig the root cause, let's start with adding the following comment

_*test_*

It's translated into html

<em><strong>test</em></strong>

from frontend through method call buildOptimisticAddCommentReportAction => getParsedComment => ExpensiMark.replace.

In method ExpensiMark.replace, the italic rule translates the markdown to

<em>*test</em>*

and then the bold rule translate the above intermediate html to

<em><strong>test</em></strong>

We find the tag <em> and <strong> are overlapping with each other. The backend will correct it to following HTML

<em><strong>test</strong></em>

See this SO discussion about overlapping tags.

So when editing the comment, the html corrected by the backend is translated to

_*test*_

If we change the markdown to

_*test_*

and save it again. The frontend will again translate it into the overlapping html

<em><strong>test</em></strong>

through method call editReportComment => handleUserDeletedLinksInHtml => ExpensiMark.replace.

And as the overlapping html is different from the original html corrected by the backend, so the overlapping html is saved to backend again. But after the backend corrects the overlapping html and compares with original html, it figures out that frontend sends the same html to save. So the backend returns empty text to frontend and the comment disappears on frontend.

So the root cause is that the italic rule and bold rule creates overlapping tags.

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

To fix this issue, I think we can have a method to validate if the text of an element tag includes non-paired tags. For example, if the text g1 of <strong> tag is test</em>, then it contains non-paired tag and we skip to format it.

We can have a method containsNonPairTag, like

/**
 * Check if the input text includes only the open or the close tag of an element. 
 *
 * @param {String} textToCheck - Text to check
 * 
 * @returns {Boolean}
 */
containsNonPairTag(textToCheck) {
    const matchedTagPairs = textToCheck.match(/<(.*)\b[^>]*>[^<>]*<\/\1>/gm) || [];
    const matchedTags = textToCheck.match(/<[^>]*>/gm) || [];
    
    if (matchedTagPairs.length * 2 !== matchedTags.length) {
        return true;
    }
    return false;
}

and use it to by change condition from

replacement: (match, g1) => (g1.includes('<pre>') ? match : `<strong>${g1}</strong>`),

to

replacement: (match, g1) => (g1.includes('<pre>') || this.containsNonPairTag(g1) ? match : `<strong>${g1}</strong>`),

We can apply similar fix for <em>, <strong> and <del> tags.

What alternative solutions did you explore? (Optional)

We can also fix the overlapping HTML from frontend in the same way as the backend does.

@melvin-bot melvin-bot bot added the Overdue label May 1, 2023
@eVoloshchak
Copy link
Contributor

Reviewing the proposals today

@melvin-bot melvin-bot bot removed the Overdue label May 1, 2023
@NicMendonca NicMendonca removed their assignment May 22, 2023
@NicMendonca NicMendonca added Bug Something is broken. Auto assigns a BugZero manager. and removed Bug Something is broken. Auto assigns a BugZero manager. labels May 22, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 22, 2023

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

@melvin-bot

This comment was marked as off-topic.

@zanyrenney
Copy link
Contributor

Did you not hire any of the people to the upwork issue @NicMendonca ? I can't see anyone hired.

@zanyrenney
Copy link
Contributor

Unfortunately - Upwork is having a site outage when I try to hire them
2023-05-24_14-25-59

@zanyrenney
Copy link
Contributor

offers sent @eVoloshchak @eh2077

@eh2077
Copy link
Contributor

eh2077 commented May 24, 2023

@zanyrenney Accepted. Thank you!

@zanyrenney
Copy link
Contributor

Going OOO and this is pretty active so needs management by bug0 team member, as per the new process to stay assigned but assign another team member, please can you keep a watch of this. I am OOO until 8th June. Thanks!

@zanyrenney zanyrenney removed their assignment May 25, 2023
@zanyrenney zanyrenney added Bug Something is broken. Auto assigns a BugZero manager. and removed Bug Something is broken. Auto assigns a BugZero manager. labels May 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 25, 2023

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

@melvin-bot

This comment was marked as off-topic.

@Christinadobrzyn
Copy link
Contributor

Catching up here,

@eVoloshchak is C+ - hired in Upwork
@eh2077 is contributor - hired in Upwork

Upwork job - https://www.upwork.com/jobs/~01fbc70abb602fff25

Does the speed bonus apply to this? I can't find the original PR for this fix @deetergp @eVoloshchak @eh2077

Also, do we need a regression test for this?

@deetergp
Copy link
Contributor

@Christinadobrzyn the original PR is here. Not sure if the bonus applies or not.

@Christinadobrzyn
Copy link
Contributor

  • Thanks @deetergp! It looks like a speed bonus does not apply: PR created May 8th and merged May 15th

  • Paid @eh2077 and @eVoloshchak in Upwork - closed job in Upwork

  • @eVoloshchak or @eh2077 I think a regression test would apply here, please feel free to send over the testing steps if you agree! thanks!

@luacmartins
Copy link
Contributor

Have we bumped the package's version in App yet?

@deetergp
Copy link
Contributor

@luacmartins, Short answer: yes. The long answer is hidden in the back-scroll.

@luacmartins
Copy link
Contributor

All I need is the short answer :) Thanks!

@eVoloshchak
Copy link
Contributor

Regression Test Proposal

  • Send a message _*text*_
  • Edit message to _*text_*
  • Verify the message doesn't disappear
  • Verify the text is formatted in italics and isn't formatted in bold style

Do we agree 👍 or 👎

@Christinadobrzyn
Copy link
Contributor

Regression test here - https://github.com/Expensify/Expensify/issues/287343

I think this GH is ready to close? @deetergp @luacmartins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review
Projects
None yet
Development

No branches or pull requests

10 participants