App icon indicating copy to clipboard operation
App copied to clipboard

[$175] Composer - Input field renders at two-line height before typing starts

Open m-natarajan opened this issue 1 month ago • 42 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: Reproducible in staging?: Needs Reproduction (Unable to reproduce) Reproducible in production?: Needs Reproduction If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @AndrewGable Slack conversation (hyperlinked to channel name): #Expensify Bugs

Action Performed:

  1. Open a DM
  2. Look at the composer ("Write something...") before typing anything.
  3. Start typing a message.

Expected Result:

The composer should render at a single-line height by default

Actual Result:

The composer appears at a two-line height while empty/showing the placeholder

Workaround:

Unknwon

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome / Safari

Screenshots/Videos

Image

View all open jobs on GitHub

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

m-natarajan avatar Oct 08 '26 16:10 m-natarajan

Proposal

Reproduced on web. The bug happens when you send a restored draft without editing it, and the draft was one long line that wrapped to 2 lines:

  1. In a DM, type one long line that wraps to 2 lines. Do not use Enter or Shift+Enter.
  2. Leave the chat and come back, or reload, so the composer reloads with the draft.
  3. Send it without editing.
  4. The empty composer stays at 2-line height, with the placeholder at the top, until you type.

Sending a newly typed multi-line message does not trigger it. This explains why QA could not reproduce it.

What is the root cause of that problem?

The composer saves the first height it measures as the "empty" height. The guard only skips text that contains \n. See ComposerWithSuggestions.tsx:1007-1009.

When the composer loads with a long wrapped draft, its first measurement is 2 lines tall. That value is saved as the "empty" height, because the draft has no \n.

On send, resetHeight() fixes the composer at that saved 2-line height. The fixed height is only removed when onContentSizeChange fires (:1004) or when the user types (:689). The new height matches the last measured height, so no size change fires. The composer stays at 2 lines.

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

In ComposerWithSuggestions.tsx:

  1. Save the empty height only when the input is actually empty (valueRef.current === ''), not just when it has no \n.
  2. Stop relying on onContentSizeChange to remove the fixed height. Clear composerHeightAfterClear on the next animation frame after it is set.

Part 2 alone fixes the stuck state. Part 1 stops the wrong value from being saved. Retest the cursor flash fixed in Fix cursor moves to write something briefly with expand compose box, which added this height-reset logic.

What alternative solutions did you explore? (Optional)

Compute the empty height from styles (line height plus vertical padding) instead of measuring it.

Reproduction screenshots (web, dev)

Restored 2-line draft before sending:
Composer reopened with a restored draft that wraps to 2 lines

Empty composer still taller than one line, 3 seconds after sending:
Empty composer still taller than one line 3s after sending

Back to one line after typing one character:
Composer back to one line after typing a character

The tester measured heights from screenshots. It could not read DOM values directly.

Other details
  • Ruled out a whitespace-only draft. The placeholder only shows when the input is truly empty (:empty::before in react-native-live-markdown).
  • Possible second trigger (not verified): the composer is first measured while the window is narrow or a side panel is animating in.
  • Allow editing messages in Composer on narrow screens V2 reworked this code and the resetHeight call in useComposerSubmit.ts:178. No PR from August to October 2026 changed it.

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


view run · view recording

MelvinBot avatar Oct 08 '26 17:10 MelvinBot

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

melvin-bot[bot] avatar Oct 08 '26 17:10 melvin-bot[bot]

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

melvin-bot[bot] avatar Oct 08 '26 17:10 melvin-bot[bot]

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

Proposal

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

In a chat or DM, the message composer renders at a two-line height while empty and showing the placeholder ("Write something..."), instead of rendering at a single-line height. The composer remains stuck at two lines until the user starts typing.

What is the root cause of that problem?

In src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions.tsx (lines 1007–1009):

// Store the default collapsed composer height, so we can later reset the height when we clear the input.
if (emptyComposerHeightRef.current === null && inputHeight > 0 && !valueRef.current.includes('\n')) {
    emptyComposerHeightRef.current = inputHeight;
}
  1. The code attempts to measure and store the initial collapsed height of an empty composer into emptyComposerHeightRef.current. However, it uses !valueRef.current.includes('\n') as the predicate. If a draft message was restored upon opening the report (or typed without explicit newlines) that wraps across 2 lines, its height exceeds a single line but contains no \n. Consequently, emptyComposerHeightRef.current captures the 2-line wrapped height instead of the single-line baseline height.
  2. When the user sends the draft message, resetHeight() (lines 850–855) assigns setComposerHeightAfterClear(emptyComposerHeightRef.current), locking the empty composer to the erroneously stored 2-line height.
  3. clearComposerHeight() is only called inside handleContentSizeChange. Because the empty input does not fire a subsequent content size change event after submission, the composer stays pinned to the 2-line height until the user types.

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

In src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions.tsx:

  1. Only record baseline height when input is truly empty: Update the condition in handleContentSizeChange so emptyComposerHeightRef.current is only captured when the input contains no text:

    if (emptyComposerHeightRef.current === null && inputHeight > 0 && valueRef.current.trim() === '') {
        emptyComposerHeightRef.current = inputHeight;
    }
    

    This guarantees that long wrapped drafts or multi-line messages without newlines never poison emptyComposerHeightRef.current.

  2. Auto-release temporary height lock after clear: In resetHeight(), schedule clearComposerHeight() via requestAnimationFrame so the temporary height lock applied during submission prevents cursor flashing/jumping while immediately relinquishing fixed height back to flex layout:

    const resetHeight = useCallback(() => {
        if (!emptyComposerHeightRef.current) {
            return;
        }
        setComposerHeightAfterClear(emptyComposerHeightRef.current);
        requestAnimationFrame(() => {
            clearComposerHeight();
        });
    }, [clearComposerHeight]);
    

What alternative solutions did you explore? (Optional)

  • Hardcoding line height constants: Calculating height statically using font size and vertical padding misses platform-specific font rendering metrics (Android vs iOS vs Web). Capturing the true measured height when valueRef.current.trim() === '' preserves exact native measurement without hardcoding.

What specific scenarios should we cover in automated tests?

In tests/unit/ComposerWithSuggestionsTest.tsx:

  1. When handleContentSizeChange fires with non-empty text lacking newlines (e.g. wrapped draft), verify that emptyComposerHeightRef.current is not set.
  2. When handleContentSizeChange fires with empty text (""), verify that emptyComposerHeightRef.current is recorded.
  3. Verify that sending a multi-line or wrapped message resets the composer to the single-line height and releases the fixed height lock.

RajGahoi avatar Oct 08 '26 17:10 RajGahoi

:warning: Unable to store contributor details

Details
Auth SetContributorDetails returned an error
401 Contributor details already exist

melvin-bot[bot] avatar Oct 08 '26 17:10 melvin-bot[bot]

Proposal

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

The empty message composer can remain at a two-line height instead of collapsing back to the normal single-line height after a restored wrapped draft is sent.

What is the root cause of that problem?

The composer caches its "empty" height from the first measured content height using a condition that only excludes values containing a newline.

A restored draft can wrap onto two visual lines without containing \n. In that case the composer records that wrapped two-line measurement as emptyComposerHeightRef.current. When the draft is sent, resetHeight() restores that incorrect cached value, so the now-empty composer remains two lines tall until another content-size change or user input clears the fixed height.

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

  • Only record emptyComposerHeightRef.current when the composer value is actually empty, not merely newline-free.
  • Ensure the temporary fixed height used during clear/reset is released deterministically after the reset instead of depending only on a subsequent onContentSizeChange.
  • Keep the existing anti-flicker behavior intact and add regression coverage for a restored long single-line draft that visually wraps, is sent without editing, and must return to the normal one-line empty composer height.

What alternative solutions did you explore? (Optional)

Hardcoding the single-line height would avoid the stale measurement but would be more fragile across platforms/font metrics. Reusing the measured empty state is safer as long as it is captured only from a truly empty composer.

krsnak avatar Oct 08 '26 17:10 krsnak

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

Proposal

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

In a chat or DM, after sending a restored wrapped draft message, the empty composer remains stuck at a two-line height with the placeholder visible, instead of collapsing back down to a single-line height.

What is the root cause of that problem?

In src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions.tsx (lines 1006–1009):

// Store the default collapsed composer height, so we can later reset the height when we clear the input.
if (emptyComposerHeightRef.current === null && inputHeight > 0 && !valueRef.current.includes('\n')) {
    emptyComposerHeightRef.current = inputHeight;
}
  1. The code attempts to cache the baseline empty collapsed composer height into emptyComposerHeightRef.current. However, it guards with !valueRef.current.includes('\n').
  2. When a chat is opened with an existing restored draft that visually wraps onto 2 lines without containing an explicit newline (\n), the first handleContentSizeChange measurement captures the 2-line wrapped height and erroneously stores it into emptyComposerHeightRef.current.
  3. When the user submits the draft without editing, resetHeight() (lines 850–855) sets composerHeightAfterClear to emptyComposerHeightRef.current (2-line height).
  4. clearComposerHeight() is only triggered when a subsequent handleContentSizeChange or onChangeText event occurs. Because the input is now empty and no new text is being typed, no further content size changes fire, leaving the composer pinned to the 2-line height until the user starts typing.

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

In src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions.tsx:

  1. Only record baseline collapsed height when the input is actually empty:
if (emptyComposerHeightRef.current === null && inputHeight > 0 && valueRef.current.trim() === '') {
    emptyComposerHeightRef.current = inputHeight;
}

This guarantees that wrapped drafts without newlines will never contaminate emptyComposerHeightRef.current.

  1. Handle fallback and release height lock deterministically in resetHeight():
const resetHeight = useCallback(() => {
    if (!emptyComposerHeightRef.current) {
        // If the composer mounted with an existing draft and emptyComposerHeightRef was never recorded,
        // clear the manual height immediately to let natural flexbox layout collapse to 1 line
        setComposerHeightAfterClear(null);
        return;
    }
    setComposerHeightAfterClear(emptyComposerHeightRef.current);
    requestAnimationFrame(() => {
        clearComposerHeight();
    });
}, [clearComposerHeight]);

Why this works:

  • If the chat was opened empty, emptyComposerHeightRef.current cleanly records the true 1-line measured height. When submitting any multi-line or wrapped message, resetHeight() locks it to 1 line to prevent layout flashing, then releases it on the next paint frame via requestAnimationFrame.
  • If the chat was opened with an existing draft (where emptyComposerHeightRef was never set), resetHeight() explicitly resets setComposerHeightAfterClear(null), allowing the empty TextInput to naturally collapse to 1 line via flexbox with zero stuck height.

What alternative solutions did you explore? (Optional)

  • Hardcoding line height constants: Calculating height statically using font size and padding misses platform-specific font metrics and OS font scaling (iOS Dynamic Type, Android font scaling). Measuring dynamically when valueRef.current.trim() === '' with an unconstrained fallback is safer and cross-platform native.

ashusatyarthi-wq avatar Oct 08 '26 18:10 ashusatyarthi-wq

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

melvin-bot[bot] avatar Oct 08 '26 18:10 melvin-bot[bot]

Proposal

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

The empty message composer renders stuck at a two-line height with the placeholder visible instead of collapsing back down to a single-line height after sending a draft.

What is the root cause of that problem?

In src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions.tsx:

  1. Lines 1010–1013:
if (emptyComposerHeightRef.current === null && inputHeight > 0 && !valueRef.current.includes('\n')) {
    emptyComposerHeightRef.current = inputHeight;
}

The check uses !valueRef.current.includes('\n'). When a conversation opens with an existing saved draft that visually wraps onto 2 lines without explicit newline characters (\n), the initial handleContentSizeChange measures the 2-line wrapped height and incorrectly saves it as emptyComposerHeightRef.current. 2. When the user sends the draft, resetHeight() sets composerHeightAfterClear to emptyComposerHeightRef.current (which is poisoned with the 2-line measurement). Because the composer is now empty and no subsequent input events fire, clearComposerHeight() is never called, leaving the empty composer stuck at 2-line height.

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

In src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions.tsx:

  1. Only record baseline collapsed height when the input is actually empty (valueRef.current.trim() === ''):
if (emptyComposerHeightRef.current === null && inputHeight > 0 && valueRef.current.trim() === '') {
    emptyComposerHeightRef.current = inputHeight;
}
  1. In resetHeight(), if emptyComposerHeightRef.current was not recorded (e.g., opened with an existing long draft), reset setComposerHeightAfterClear(null) immediately to allow native flex layout to settle at single-line height.
  2. Automatically release the temporary height lock via requestAnimationFrame(() => clearComposerHeight()) so layout flickering is prevented during message submission while ensuring the composer returns to natural single-line height.

Tested and pre-coded on branch fix/103497-composer-empty-height.


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

jloa-dev avatar Oct 10 '26 03:10 jloa-dev

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

melvin-bot[bot] avatar Oct 10 '26 03:10 melvin-bot[bot]

Can't reproduce

DylanDylann avatar Oct 13 '26 07:10 DylanDylann

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

melvin-bot[bot] avatar Oct 13 '26 07:10 melvin-bot[bot]

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

melvin-bot[bot] avatar Oct 13 '26 07:10 melvin-bot[bot]

Reassigning to someone else to see if they can reproduce it

DylanDylann avatar Oct 13 '26 07:10 DylanDylann

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

Proposal

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

The empty message composer renders stuck at a two-line height with the placeholder visible before typing starts, instead of cleanly settling at single-line baseline height.

What is the root cause of that problem?

In src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions.tsx:1010-1013:

if (emptyComposerHeightRef.current === null && inputHeight > 0 && !valueRef.current.includes('\n')) {
    emptyComposerHeightRef.current = inputHeight;
}
  1. The baseline empty height is checked with !valueRef.current.includes('\n'). If the screen mounts with an existing saved draft that wraps across two lines without hard newline characters (\n), inputHeight measures the 2-line wrapped height and incorrectly locks emptyComposerHeightRef.current to that 2-line dimension.
  2. In resetHeight(), the composer applies composerHeightAfterClear set to emptyComposerHeightRef.current. Because the input is now empty and placeholder text is displayed, emptyComposerHeightRef.current keeps the container pinned at 2-line height until manual typing occurs.

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

In src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions.tsx:

  1. Only record baseline empty height when the input is strictly empty:
if (emptyComposerHeightRef.current === null && inputHeight > 0 && valueRef.current.trim() === '') {
    emptyComposerHeightRef.current = inputHeight;
}
  1. In resetHeight(), ensure safe fallback if emptyComposerHeightRef.current was never set during a draft mount, clearing the height immediately via setComposerHeightAfterClear(null).
  2. Release the height lock cleanly on the next animation frame using requestAnimationFrame(() => clearComposerHeight()) to avoid layout flashes during send while allowing the composer to return to native single-line height.

What alternative solutions did you explore? (Optional)

Hardcoding line-height values: This fails across platforms due to distinct font rendering metrics and OS accessibility text scaling (Dynamic Type on iOS / Font Scale on Android). Dynamically evaluating valueRef.current.trim() === '' preserves native responsiveness.

camesenin avatar Oct 13 '26 16:10 camesenin

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

melvin-bot[bot] avatar Oct 13 '26 16:10 melvin-bot[bot]

@situchan Whoops! This issue is 2 days overdue. Let's get this updated quick!

melvin-bot[bot] avatar Oct 16 '26 21:10 melvin-bot[bot]

Reproduced on web (local dev build of main @ abff087, Windows 11, Chrome).

  1. Open any chat. Type one long line that wraps to 2 lines. Don't press Enter or Shift+Enter.
  2. Switch to another chat in the LHN, then switch back. The draft is restored.
  3. Send the draft without editing it.
  4. The empty composer stays at the 2-line height with the placeholder at the top. It measured 56px with an inline height: 56px, against 36px normally. It stayed that way for over 10 seconds and only went back to normal after I typed a character.

Two details that may explain why it's hard to reproduce:

  • The return has to be in-app navigation. Coming back with a browser reload did not reproduce it for me. After a reload the composer resets to 36px after sending.
  • Once it happens, every later send in that chat also leaves the composer at 2 lines, even for freshly typed messages, until the composer remounts. On a fresh load, a freshly typed wrapped message resets correctly.

Both match emptyComposerHeightRef in ComposerWithSuggestions.tsx (L1009-1010). It is set once per mount, from the first measured height of text with no \n, so a restored wrapped draft saves the 2-line height as the "empty" height.

Before / after:

Image Image

mukesh-dev-git avatar Oct 19 '26 19:10 mukesh-dev-git

📣 @mukesh-dev-git! 📣 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 Oct 19 '26 19:10 melvin-bot[bot]

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

mukesh-dev-git avatar Oct 20 '26 06:10 mukesh-dev-git