Skip to content

[Due for payment 2025-09-17] [$250] Chat - Formatting is incorrect when pasting code into the compose box #62848

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: v9.1.51-9
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/6048951&group_by=cases:section_id&group_order=asc&group_id=309131
Email or phone of affected tester (no customers): arkam2504+1tr@gmail.com
Issue reported by: Applause Internal Team
Device used: iOs 18 / iPhone 14 pro max
App Component: Chat Report View

Action Performed:

Preconditions: Account is created and the user is logged in

Steps to Reproduce:

  1. Navigate to this link -
    if (files.length > 0) {
    // Prevent the default so we do not post the file name into the text box
    event.preventDefault();
    this.props.onPasteFile(event.clipboardData.files[0]);
    return;
  2. Copy the text highlighted in yellow
  3. Navigate to the Expensify app
  4. Paste the code into the compose box in a conversation

Expected Result:

The pasted code should retain original formatting:

  • No extra space between lines.
  • All lines left-aligned as in the source code.

Actual Result:

Extra line spacing appears between some lines.
Some lines, such as the second-to-last one, appear visually misaligned or more indented than the others.

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

Image

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021928524455201945661
  • Upwork Job ID: 1928524455201945661
  • Last Price Increase: 2025-05-30
  • Automatic offers:
    • nkdengineer | Contributor | 107550710
Issue OwnerCurrent Issue Owner: @OfstadC

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on May 27, 2025
  2. melvin-bot commented on May 27, 2025

    @melvin-bot

    Triggered auto assignment to @OfstadC (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. nkdengineer commented on May 27, 2025

    @nkdengineer
    Contributor

    Proposal

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

    Extra line spacing appears between some lines.
    Some lines, such as the second-to-last one, appear visually misaligned or more indented than the others.

    What is the root cause of that problem?

    We're using white-space: pre

    for comment, so

    Sequences of white space are preserved. Lines are only broken at newline characters in the source and at
    elements.

    Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

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

    We should replace the white-space with   in

    html={htmlWithTag.replace(/(?:(?![\n\r])\s)/g, ' ')}
    

    I referred this regex in https://github.com/Expensify/expensify-common/blob/14ba35584bb3619035c27368b2206842ee930aea/lib/ExpensiMark.ts#L183

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    UI issue

    What alternative solutions did you explore? (Optional)

    We can fix it in expensify-common

    https://github.com/Expensify/expensify-common/blob/14ba35584bb3619035c27368b2206842ee930aea/lib/ExpensiMark.ts#L950

    but I'm not sure if it cause the regression because it's used in too many places

    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. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on May 30, 2025
  5. melvin-bot commented on May 30, 2025

    @melvin-bot
  6. changed the title [-]Chat - Formatting is incorrect when pasting code into the compose box[/-] [+][$250] Chat - Formatting is incorrect when pasting code into the compose box[/+] on May 30, 2025
  7. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on May 30, 2025
  8. melvin-bot commented on May 30, 2025

    @melvin-bot

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

  9. shakibwebx commented on May 30, 2025

    @shakibwebx

    Proposal to Fix Issue #62848

    Hi team,

    To resolve the formatting inconsistency when pasting code into the chat compose box, I propose the following:

    🛠 Technical Plan
    The root cause is the use of white-space: pre in combination with how normal spaces are handled when rendering HTML. When pasting code, some white spaces collapse or appear uneven due to inconsistencies in how the browser interprets normal spaces vs non-breaking spaces.

    To fix this:

    Replace all normal spaces (excluding newlines) in the htmlWithTag string with  , preserving indentation and preventing extra spacing between lines.

    Implementation (in TextCommentFragment.tsx):

    tsx
    Copy
    Edit
    const formattedHTML = htmlWithTag.replace(/(?:(?![\n\r])\s)/g, ' ');
    return ;
    This will ensure:

    Line breaks are preserved (\n, \r stay intact)

    All visible spaces remain consistent

    The change is localized to TextCommentFragment, minimizing regression risk

    I will test this on:

    Web (Chrome, Safari)

    Android (native + Chrome)

    iOS (native + Safari/Chrome)

    Desktop (Electron)

    I have already prepared the code diff and can proceed with implementation upon acceptance.

    Let me know if this approach looks good!

    Thanks,
    Md Habibur Rahman

  10. melvin-bot commented on May 30, 2025

    @melvin-bot

    📣 @shakibwebx! 📣
    Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
    Please follow these steps:

    1. Make sure you've read and understood the contributing guidelines.
    2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
    3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  11. 39 remaining items

  12. MonilBhavsar commented on Sep 10, 2025

    @MonilBhavsar
    Contributor

    Caused a regression #70166 @nkdengineer @ZhenjaHorbach

  13. nkdengineer commented on Sep 10, 2025

    @nkdengineer
    Contributor

    I'll check it soon

  14. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Sep 10, 2025
  15. changed the title [-][$250] Chat - Formatting is incorrect when pasting code into the compose box[/-] [+][Due for payment 2025-09-17] [$250] Chat - Formatting is incorrect when pasting code into the compose box[/+] on Sep 10, 2025
  16. melvin-bot commented on Sep 10, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.2.8-4 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-09-17. 🎊

    For reference, here are some details about the assignees on this issue:

  17. melvin-bot commented on Sep 10, 2025

    @melvin-bot

    @ZhenjaHorbach @OfstadC The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  18. ZhenjaHorbach commented on Sep 17, 2025

    @ZhenjaHorbach
    Contributor

    @OfstadC
    We are ready for payment!

  19. ZhenjaHorbach commented on Sep 17, 2025

    @ZhenjaHorbach
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] 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: NA

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source 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: NA

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Regression Test Proposal

    Test:

    1. Copy the text
     if (files.length > 0) { 
         // Prevent the default so we do not post the file name into the text box 
         event.preventDefault(); 
         this.props.onPasteFile(event.clipboardData.files[0]); 
         return; 
    
    1. Navigate to the Expensify app
    2. Paste the code into the compose box in a conversation
    3. For iOS native: an empty line is added, it's the same as Slack
    4. For other platforms: the pasted code should retain original formatting:
    • No extra space between lines.
    • All lines left-aligned as in the source code.

    Do we agree 👍 or 👎

  20. OfstadC commented on Sep 17, 2025

    @OfstadC
    Contributor

    Payment Summary

  21. ZhenjaHorbach commented on Sep 17, 2025

    @ZhenjaHorbach
    Contributor

    Requested in ND!

  22. flaviadefaria commented on Sep 19, 2025

    @flaviadefaria
    Contributor

    Approved $250 for @ZhenjaHorbach

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.ExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions