App: [HOLD for payment 2023-05-25] [$1000] Space appears for a brief moment in the LHN message before correcting it if a codeblock has a space at the beginning

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 the app
  2. Open any report
  3. Write code block with space in beginning eg: Hello test
  4. Send the message and observe in LHN that app displays the text with space before and after few seconds, removes the text

Expected Result:

App should not display space before text in LHN

Actual Result:

App displays space before text in LHN for few seconds when we send code block with space before text in it.

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

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.4 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 Notes/Photos/Videos: Any additional supporting documentation

https://user-images.githubusercontent.com/43996225/234045675-e577a468-9b9f-4ff6-85e3-d03ee3659f4b.mp4

https://user-images.githubusercontent.com/43996225/234045720-686d0232-3b6a-47b6-a379-617523ab9200.mp4

Expensify/Expensify Issue URL: Issue reported by: @dhanashree-sawant Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1682331727011769

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~016119f8050196b168
  • Upwork Job ID: 1651553553942560768
  • Last Price Increase: 2023-05-08

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 55 (33 by maintainers)

Most upvoted comments

@sakluger completed the checklist! Thanks! Please hire on account - https://www.upwork.com/freelancers/~01212e8255b02ae924

@miljakljajic thank you. I accepted the offer. I guess this issue can be assigned to me now and the Help Wanted label can be taken off

@robertjchen, @rushatgabhane, I would like to mention that the discussion in another issue https://github.com/Expensify/App/issues/17658#issuecomment-1525815579 seems to be driving towards the direction of removing usage of parser.htmlToText(htmlText).

If that is the case, then I believe my proposal would be the only working solution.


The issue highlighted in eh2077’s https://github.com/Expensify/App/issues/17896#issuecomment-1529819923 is about when the code block starts with first lines having only newline and optionally some space characters.

While newline is not exactly part the problem reported in this issue, it can also be handled within formatReportLastMessageText as well. e.g.

    return String(messageText)
        .replace(/^\s*/, '')  // will create REGEX const in actual PR
        .replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '')
        .substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH)
        .trim();

Please let me know if I should include that in my proposal as well. Thanks.

Proposal

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

Space appears for a brief moment in the LHN message before correcting it if a codeblock has a space at the beginning.

What is the root cause of that problem?

When sending a code block with leading spaces

```   test```

We build optimistic report data through method buildOptimisticAddCommentReportAction and parse the markdown code fence into html through method ExpensiMark.replace. In the codeFence-to-html rule, we replace whitespace with html code  .

In method buildOptimisticAddCommentReportAction, the code block is translated into message html string

<pre>&#32;&#32;&#32;test</pre>

and the message html string is converted to message text string here through method ExpensiMark.htmlToText.

&#32;&#32;&#32;test

Then we format optimistic data of lastMessageText for LHN here

https://github.com/Expensify/App/blob/8d661d22f85c23749ea2421131f9975551fed214/src/libs/actions/Report.js#L205-L209

by extracting the first row of message text, &#32;&#32;&#32;test, and decode it with Str.htmlDecode to get lastMessageText, ' test'.

So before backend return the trimmed lastMessageText, the LHN message will display ' test'.

When editing the code block message, we also convert message html string into text string, extract the first line and decode it with Str.htmlDecode to get optimistic lastMessageText. So same issue with adding comment.

Based on the above analysis, the root cause of this issue can be that, in method ExpensiMark.htmlToText, we don’t replace &#32; back to space and trim the text before return.

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

To fix this issue, we can replace &#32; back to space and trim the text before return in method ExpensiMark.htmlToText.

We can add a new rule to htmlToTextRules to replace &#32; to space, like

{
    name: 'replaceClassicSpaces',
    regex: /&#32;/gi,
    replacement: ' ',
}

And trim the text before return here.

What alternative solutions did you explore? (Optional)

N/A