App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-12-08] [$175] Inline editing an expense description strips line breaks and Markdown

Open luacmartins opened this issue 5 days ago • 17 comments

Editing an expense description inline on desktop flattens it to plain text. Saving even a small edit overwrites the original line breaks and Markdown.

This is follow-up #3 from #82534, tracked separately as discussed here. The line-break issue was also reported in #88651 and deferred to a follow-up.

Action Performed

  1. On desktop, create an expense and set its description from the expense details page:
    Client dinner with *Acme Corp*
    Attendees: John, Sarah
    
  2. Open the expense table in the report or Search and click the Description cell to edit it inline.
  3. Add ! at the end and press Enter to save.
  4. Reopen the expense details.

Expected Result

The description keeps its line break and Acme Corp stays bold. Only the ! is added.

Actual Result

The editor shows one line of plain text. The saved description is Client dinner with Acme Corp Attendees: John, Sarah!, without the line break or bold formatting.

Workaround

Edit the description from the expense details page instead of the table cell.

Issue OwnerCurrent Issue Owner: @ahmedGaber93
Upwork Automation - Do Not Edit

luacmartins avatar Nov 26 '26 17:11 luacmartins

cc @ahmedGaber93

luacmartins avatar Nov 26 '26 17:11 luacmartins

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

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

Proposal

What is the root cause of that problem?

The inline editor uses the display-only, flattened description as its editable value. Stored formatting is removed and line breaks become spaces before editing begins. Adding ! then saves that entire flattened value, replacing the original description.

There is also an input configuration gap: descriptions are treated as multiline in the change handler, but the actual input is not configured as multiline.

Confidence: Medium — both table paths and the save pipeline were traced in code; browser reproduction was not performed.

Code evidence
  • Formatting is lost before editing: MerchantCell.tsx:34–55 applies htmlToText and lineBreaksToSpaces, then passes the result into useInlineEditState. Its description change handler already preserves incoming text; the merchant-only sanitizer is not the cause.
  • The input remains single-line: MerchantCell.tsx:87–109 supplies neither multiline nor auto-growing configuration.
  • A small edit commits the whole damaged value: useInlineEditState.ts:59–77 calls onSave(localValue) when it differs from the initial value. Opening and leaving unchanged should not save.
  • Saving cannot recover deleted formatting: UpdateMoneyRequest.ts:1603–1652 parses that replacement and sends it as the updated description.
  • Both Search and report tables use the shared transaction-row editing implementation.

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

Separate the table preview from the editable description:

  1. Keep the existing single-line, plain-text preview.
  2. Initialize description editing with HTML converted back to Markdown, matching the full description page—not raw stored HTML.
  3. Configure descriptions as multiline inputs, preferably using the existing Markdown input. Preserve Enter-to-save, blur-to-save, Escape cancellation, and merchant-specific behavior.
  4. Add regression coverage for formatted multiline descriptions, appending !, unchanged blur, cancellation, multiline paste, and unchanged merchant behavior. Verify both Search and report tables on web.
Reference implementation and validation

The full description page already converts stored HTML to editable Markdown and uses an auto-growing Markdown input.

Browser verification should specifically check that enabling multiline preserves existing line breaks while plain Enter still saves.

What alternative solutions did you explore?

  • Use raw stored HTML: Incorrect—the editable representation should be Markdown, as in the full editor.
  • Change only the initial value: Incomplete—the input must also support multiline content, and the preview must remain separate.
  • Investigate response ordering: This cannot explain formatting already missing before save.

Related issues: Expense description reverts after saving concerns stale values after saving; Rules Markdown is not saved concerns a separate rule-writing path. Neither is established as a duplicate.


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/108117) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Nov 26 '26 17:11 MelvinBot

@ahmedGaber93, is the $175 bounty still available to an external contributor for #108117, or do you plan to have Melvin implement its proposal? I can verify the behavior in both the report and Search tables and add a regression test covering a formatted, multiline description.

Hamidou Anne

hamidouanne77-arch avatar Nov 26 '26 17:11 hamidouanne77-arch

📣 @hamidouanne77-arch! 📣 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>

melvin-bot[bot] avatar Nov 26 '26 17:11 melvin-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01c2c6c9e79bc6ca14

hamidouanne77-arch avatar Nov 26 '26 17:11 hamidouanne77-arch

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 26 '26 17:11 melvin-bot[bot]

Proposal

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

When inline-editing an expense Description cell in desktop tables (both Report and Search tables), the cell strips Markdown formatting and flattens line breaks into spaces as soon as editing starts. Making any edit and saving overwrites the stored HTML description with that flattened plain text.

What is the root cause of that problem?

In src/components/TransactionItemRow/DataCells/MerchantCell.tsx, MerchantOrDescriptionCell conflates the single-line plain-text display value with the editable description value and leaves the underlying TextInput single-line:

  1. Display-only plain text is fed into useInlineEditState (MerchantCell.tsx:34-44):
    const text = !isDescription ? merchantOrDescription : StringUtils.lineBreaksToSpaces(Parser.htmlToText(merchantOrDescription));
    
    text strips HTML formatting via Parser.htmlToText and collapses newlines via StringUtils.lineBreaksToSpaces, then passes that flattened string as the initial edit buffer to useInlineEditState. In contrast, the full description editor (src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx:95-97) converts stored HTML into editable Markdown via Parser.htmlToMarkdown(...).
  2. Single-line TextInput strips newlines even though isMultilineInput is declared (MerchantCell.tsx:46, 87-103): const isMultilineInput = isDescription; is only checked in handleChangeText (lines 48-55) and is never forwarded to <TextInput>. Without multiline / autoGrowHeight / type="markdown", React Native Web renders a single-line <input>, which strips immediately.
  3. Display rendering currently binds to localValue (MerchantCell.tsx:106-112): <TextWithTooltip text={localValue} numberOfLines={1} ... /> renders localValue directly when not editing. Once useInlineEditState buffers Markdown for descriptions, binding TextWithTooltip to localValue would leak raw Markdown syntax (e.g., *Acme Corp*) and raw newlines into the collapsed table cell.
  4. Inline-cell input styles conflict with auto-growing Markdown height (src/styles/index.ts:1565-1574 & src/components/TextInput/BaseTextInput/implementation/index.tsx:370-372, 417-428): styles.editableCellInputStyle sets height: '100%' on both textInputContainerStyles and touchableInputWrapperStyle. Inside BaseTextInput, isAutoGrowHeightMarkdown also applies {minHeight: variables.componentSizeLarge} and pb2/pb1 padding. Passing autoGrowHeight + type="markdown" without a multiline-safe cell override causes fixed-height clipping or vertical row jumps on single-line descriptions.

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

  1. Decouple display preview from the editable Markdown buffer in src/components/TransactionItemRow/DataCells/MerchantCell.tsx:

    • Keep the collapsed single-line plain-text preview separate:
      const displayText = !isDescription ? merchantOrDescription : StringUtils.lineBreaksToSpaces(Parser.htmlToText(merchantOrDescription));
      const editableValue = !isDescription ? merchantOrDescription : Parser.htmlToMarkdown(merchantOrDescription);
      
    • Pass editableValue into useInlineEditState(...) so opening inline edit loads Markdown with preserved line breaks (Client dinner with *Acme Corp* Attendees: John, Sarah), matching DynamicIOURequestStepDescription.tsx:95-97 and satisfying containsHtmlTag validation in src/libs/actions/TransactionInlineEdit.ts:329-332 (editTransactionDescriptionInline).
    • Pass text={isDescription ? displayText : localValue} to <TextWithTooltip> so both wide table cells (TransactionItemRowWide.tsx:461) and narrow titles (TransactionItemRowNarrowTitle.tsx:36) continue rendering clean single-line plain text when not editing (and refresh immediately via optimistic Onyx writes from updateMoneyRequestDescription).
    • Align description normalization in getNormalizedValue with editTransactionDescriptionInline (StringUtils.removeInvisibleCharacters(value) for descriptions, which retains internal via .split(' ')...join(' ').trim(), keeping value.trim() for merchants) so opening and blurring without real edits or adding only trailing invisible characters does not trigger redundant UPDATE_MONEY_REQUEST_DESCRIPTION calls.
  2. Enable auto-growing Markdown multiline editing for descriptions in MerchantCell.tsx while keeping Enter to save and Shift+Enter for newlines:

    • When isDescription is true, pass type="markdown", multiline, autoGrowHeight, and maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight} to <TextInput> (leaving merchant editing unchanged as single-line).
    • Add an onKeyPress handler for isDescription on web (following SearchNLFilterContent.tsx:125-136, guarded with isEnterWhileComposition):
      • Plain Enter (without shiftKey and not composing): e.preventDefault(); save(); so pressing Enter saves without inserting an unwanted trailing newline.
      • Shift+Enter: allowed through so users can insert new lines inline.
      • Escape: continues calling handleEscape via useKeyboardShortcut, resetting to editableValue without saving.
    • Add a multiline-safe style adjustment (e.g., height: 'auto' and compact minHeight matching editableCellHeight / 0 instead of height: '100%' and componentSizeLarge) for the description inline editor so single-line descriptions keep compact row height while multi-line descriptions expand cleanly up to maxAutoGrowHeight and scroll internally, preserving handleFocus (scrollToBottom + moveSelectionToEnd).
  3. Add unit/component regression tests:

    • Cover MerchantOrDescriptionCell with isDescription for:
      • Stored HTML with Markdown + <br /> (e.g., Client dinner with <strong>Acme Corp</strong><br />Attendees: John, Sarah): collapsed TextWithTooltip shows plain single-line text, entering edit mode populates Markdown with , appending ! and pressing Enter calls onSave with Markdown + intact.
      • Shift+Enter inserts a newline without saving; IME composition Enter does not prematurely save.
      • Blur without edits does not call onSave; Escape cancels and restores editableValue.
      • Merchant cell (isDescription={false}) keeps single-line sanitization (lineBreaksToSpaces) and trimming unchanged.
    • Verify end-to-end in both Report and Search tables on desktop web.

What alternative solutions did you explore? (Optional)

  • Initializing the editor with raw stored HTML (merchantOrDescription): Rejected — users would see raw tags like <strong> / <br />, and editTransactionDescriptionInline (src/libs/actions/TransactionInlineEdit.ts:330) explicitly rejects HTML tags with common.error.invalidCharacter.
  • Using autoGrowSingleLine on BaseTextInput: Rejected — BaseTextInput's autoGrowSingleLine intercepts Shift+Enter to submit (src/components/TextInput/BaseTextInput/index.tsx:22-32), which would prevent inserting line breaks in multiline descriptions.
  • Plain multiline TextInput without type="markdown": Works for preserving Markdown characters as raw text, but type="markdown" matches DynamicIOURequestStepDescription.tsx:244 so users get live Markdown formatting and consistent HtmlPasteHandler paste behavior when editing descriptions inline.

📣 @elghaffaryoussef1-dotcom! 📣 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>

melvin-bot[bot] avatar Nov 26 '26 18:11 melvin-bot[bot]

Proposal

What is the root cause of that problem?

There are three causes in MerchantCell.tsx, the cell used for the Description column.

  1. The editor starts from the display text. L34 turns the stored HTML into plain text and turns line breaks into spaces. That one value is passed to useInlineEditState (L39-44). It becomes localValue, which is both the editor value (L90) and the preview text (L106-112). The hook also resets localValue to this same value (L35-38, L46-51). Any edit then sends the flattened text through editTransactionDescriptionInline to updateMoneyRequestDescription, which parses it as Markdown. The * marks and line breaks are already gone, so the saved HTML is one plain line. The description page does it right: it edits Parser.htmlToMarkdown(...) in a Markdown input that grows.

  2. The input is single-line. L46 sets isMultilineInput for descriptions, but it is only used in handleChangeText. The TextInput (L87-103) gets no multiline, autoGrowHeight or type="markdown", so on web it renders a single-line <input> (BaseTextInput L348, L563). The browser drops line breaks from a single-line input by itself. So fixing only cause 1 would still lose line breaks.

  3. The cell style blocks a taller input. The cell passes editableCellInputStyle (L99-100), which sets height: '100%'. That pins the input to the row height, so a multi-line description cannot be shown even if the input were multi-line.

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

All changes are in MerchantCell.tsx, for descriptions only. Merchant stays as it is.

  1. Split the preview from the edit value.

    • Edit value (passed to useInlineEditState): Parser.htmlToMarkdown(description), the same as the description page.
    • Preview: compute lineBreaksToSpaces(htmlToText(description)) from the prop and pass it to TextWithTooltip, instead of localValue. If we only change the edit value, the one-line preview would show raw Markdown like *Acme Corp*.
    • Since the hook compares the new value with the edit value, opening and leaving without a change still does not save.
  2. Make the input a growing Markdown input. Add multiline, autoGrowHeight, a maxAutoGrowHeight and type="markdown" to the description TextInput. Keep submitBehavior="blurAndSubmit", onSubmitEditing={save} and onBlur={save}. With the existing react-native-web submitBehavior patch, plain Enter saves and Shift+Enter adds a new line. Do not use autoGrowSingleLine: it makes Shift+Enter save too (BaseTextInput L20-37), so a user could never add a line.

  3. Let the description input grow. For descriptions, override height: '100%' with height: 'auto' and a max height that scrolls inside the input. A one-line description then looks like today's input, and a multi-line one gets a taller box. This matches the design direction in #83127 ("wrapped ones to be taller inputs and the ones that don't have a regular input"). The existing handleFocus already moves the cursor to the end and scrolls to the bottom, so long values open at the end.

  4. Tests (MerchantCell / inline edit tests):

    • Stored Client dinner with <strong>Acme Corp</strong><br />Attendees: John, Sarah: the editor shows Client dinner with *Acme Corp*\nAttendees: John, Sarah, and adding ! saves ...*Acme Corp*\nAttendees: John, Sarah!.
    • The preview stays one line of plain text.
    • Open and blur without a change does not save. Escape cancels.
    • Merchant cell stays single-line and still turns pasted line breaks into spaces.

Pseudo-code:

preview   = isDescription ? lineBreaksToSpaces(htmlToText(value)) : value
editValue = isDescription ? htmlToMarkdown(value) : value
useInlineEditState(canEdit, editValue, ...)
TextInput: isDescription -> multiline, autoGrowHeight, maxAutoGrowHeight, type="markdown", height auto
TextWithTooltip text = preview

What alternative solutions did you explore? (Optional)

  • Edit the stored HTML as is. Rejected: users would see <strong> and <br /> tags, and editTransactionDescriptionInline rejects HTML tags.
  • Open the full description page from the cell when the description has several lines or Markdown. Rejected: it works, but it drops inline editing for those expenses, which is the feature this follow-up is for.

mattlsyyssll avatar Nov 26 '26 19:11 mattlsyyssll

Proposal Please re-state the problem that we are trying to solve in this issue. On desktop, inline-editing an expense description from the expense table (report table or Search) flattens it to plain text: saving even a tiny edit (e.g. adding !) overwrites the original description, losing its line breaks and Markdown formatting (e.g. Acme Corp bold). Editing from the full expense details page does not lose formatting. What is the root cause of that problem? I verified the diagnosis against the code on main. The formatting is destroyed before editing even begins, in MerchantOrDescriptionCell (src/components/TransactionItemRow/DataCells/MerchantCell.tsx), which renders both the merchant and the description cells: // MerchantCell.tsx:34 — the description's editable initial value const text = !isDescription ? merchantOrDescription : StringUtils.lineBreaksToSpaces(Parser.htmlToText(merchantOrDescription)); Parser.htmlToText strips the Markdown formatting and lineBreaksToSpaces turns newlines into spaces, and this flattened string is passed as the initial value to useInlineEditState (lines 39-44). From then on the editor only knows the damaged value, so any save overwrites the original description with it. There is a second, independent defect in the same file. The component already computes const isMultilineInput = isDescription; (line 46) and the change handler already preserves text for multiline inputs (lines 50-55) — but isMultilineInput is never passed to the (lines 87-109): no multiline prop and no auto-growing configuration. So the description editor is a single-line input even though descriptions are multiline content. The save path then commits the damage: useInlineEditState (src/components/EditableCell/useInlineEditState.ts:59-77) calls onSave(localValue) whenever the value differs from the initial value, so appending ! saves the entire flattened string. Opening the editor and leaving it unchanged does not save (the isEqual check), which is why the bug only bites once you actually edit. What changes do you think we should make in order to solve the problem?

  1. In MerchantOrDescriptionCell, initialize description editing with Markdown, not flattened plain text: use Parser.htmlToMarkdown(merchantOrDescription) (available at src/libs/Parser.ts:38) as the initial value for descriptions — the same representation the full description page already uses for editing. Keep the existing single-line plain-text preview for display (TextWithTooltip with numberOfLines={1}).
  2. Pass multiline (with auto-growing height) to the when isDescription is true, so line breaks can be entered and displayed while editing. Preserve the existing behavior: Enter to save, blur to save, Escape to cancel, and the merchant-specific sanitization (line-break stripping and trimming) untouched for non-description cells.
  3. Add regression tests for formatted multiline descriptions: append ! to a bold two-line description and verify the line break and bold survive; opening and blurring unchanged saves nothing; Escape cancels; multiline paste keeps line breaks; merchant editing behavior unchanged. Verify on both the report table and Search, on web. What alternative solutions did you explore? (Optional) • Using the raw stored HTML as the editable value: rejected — the editable representation should be Markdown, matching the full description page. • Changing only the initial value without making the input multiline: rejected — the input must also accept multiline content, otherwise newlines still cannot be entered or displayed while editing. • Fixing only the save side (e.g. merging the saved value with the original formatting): rejected — once the editor starts from a flattened value, the original formatting is unrecoverable at save time; the fix belongs at initialization. QA steps (to verify the fix)
  4. On desktop web, create an expense with a two-line description containing bold Markdown (e.g. Client dinner with Acme Corp + Attendees: John, Sarah).
  5. In the report expense table, click the Description cell, append !, press Enter, then reopen the expense details: the line break and bold formatting are preserved, only ! was added.
  6. Repeat from the Search table with the same result.
  7. Open the description cell and blur without changing anything: no save happens and the description is untouched. Press Escape mid-edit: the edit is cancelled.
  8. Regression: inline-edit a merchant (single-line) and confirm line breaks are still stripped and values are still trimmed as before.

letiggo avatar Nov 26 '26 20:11 letiggo

@ahmedGaber93, is the $175 bounty still available to an external contributor for https://github.com/Expensify/App/issues/108117

@hamidouanne77-arch We only review external proposals on issues with "Help wanted" label, so for now we will work with Melvin to fix this.

ahmedGaber93 avatar Nov 27 '26 03:11 ahmedGaber93

@MelvinBot implement this with these design requirements from the v1 inline-edit PR (#83127):

Design requirements

  1. A description that fits on one line opens in a regular one-line input, at the same height as the cell. It must not open at 2 lines or jump in height (Shawn: "It should start off as just 1 line and only grow as you add enough text to make it grow to a second line").
  2. A description that wraps or has several lines gets a taller input that grows as you type (Jon: "we'd want the wrapped ones to be taller inputs and the ones that don't have a regular input").
  3. The cursor is at the end of the text when the input opens (Shawn).
  4. Line breaks and Markdown are kept: edit the description as Markdown (Parser.htmlToMarkdown), like the description page. While not editing, the table still shows one line of plain text.

ahmedGaber93 avatar Nov 27 '26 03:11 ahmedGaber93

🤖 Web test steps verification results: ❌ fail

Infrastructure blocker; no product verdict. The browser session lost its connection and displayed a blank page, preventing verification.

Blank web page blocking inline description verification
Step Status
Create formatted, two-line descriptionBlocked by disconnected browser session.
⚠️
Report table preserves formatting and newline after saveUnverified.
⚠️
Search table preserves formatting and newline after saveUnverified.
⚠️
Short editor retains cell heightUnverified.
⚠️
Short description opens on one lineUnverified.
⚠️
Cursor opens at the endUnverified.
⚠️
Wrapped/multiline descriptions open tallerUnverified.
⚠️
Editor grows while typingUnverified.
⚠️
Shift+Enter inserts a newlineUnverified.
⚠️
Preview remains single-line plain textUnverified.
⚠️
Unchanged blur preserves descriptionUnverified.
⚠️
Escape cancels editingUnverified.
⚠️
Multiline paste retains newlinesUnverified.
⚠️
Merchant remains single-lineUnverified.
⚠️

Implemented in draft PR: Preserve Markdown and line breaks when inline editing expense descriptions, assigned to ahmedGaber93.

Passed: 180 relevant tests, TypeScript, lint, formatting, spelling, unused-style analysis, and Storybook smoke checks. Full Jest and changed-file compiler checks timed out. Browser verification remains required before marking ready for review.


view run · no recording available

MelvinBot avatar Nov 27 '26 03:11 MelvinBot

Deploy Blocker https://github.com/Expensify/App/issues/108462 was identified to be related to the PR https://github.com/Expensify/App/pull/108137 that attempted to fix this issue.

mitarachim avatar Dec 01 '26 14:12 mitarachim

@ahmedGaber93

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

  • https://github.com/Expensify/App/pull/108137

If no regressions arise, payment will be issued on 2026-12-08. :confetti_ball:

The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the Contributor+ 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]. If no checklist is needed for this issue, you can click: [no checklist button]

melvin-bot[bot] avatar Dec 01 '26 23:12 melvin-bot[bot]