Skip to content

[$250] [Exploratory] Chat - After switching to landscape mode, user can type on composer but is unable to delete. #87860

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: 9.3.59-3
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #87338
Email or phone of affected tester (no customers): ibellicotest+2250@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Motorola MotoG60 / Android 12 (Hybrid app)
App Component: Other

Action Performed:

  1. Open the Expensify app.
  2. Open any chat.
  3. Switch to landscape mode.
  4. Tap on composer.
  5. Type anything on composer but don´t send it to chat.
  6. Switch to portrait mode and return to landscape.
  7. Keep typing on composer.
  8. Note that text is being correctly added.
  9. Try to delete the text.
  10. Note that text is not deleted.

Expected Result:

After switching to landscape mode, user should be able to keep typing on composer and also deleting text.

Actual Result:

After switching to landscape mode, user is able to keep typing on composer but is unable to delete text.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Video.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022054388386991708619
  • Upwork Job ID: 2054388386991708619
  • Last Price Increase: 2026-05-13

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    and removed on May 13, 2026
  2. MelvinBot commented on May 13, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    On Android, when the user switches orientation (portrait → landscape → portrait → landscape) with the composer focused, the IME (Input Method Editor) connection to the underlying ReactEditText becomes stale. The composer uses a controlled value prop, so backspace relies entirely on the native IME's InputConnection.deleteSurroundingText — when that connection is broken, backspace events never reach React's onChangeText, and the controlled value immediately restores any natively-deleted text.

    The desync is caused by the orientation-change machinery in the native Composer:

    1. useLandscapeOnBlurProxy catches the blur that happens during rotation and re-focuses after a 100ms delay — but this blur/refocus cycle can leave the IME InputConnection in a broken state.
    2. getLandscapeTextInputRefProxy wraps the ref in a Proxy that no-ops focus() calls in landscape, so any system-initiated refocus attempts are silently swallowed.
    3. setTextInputRef is recreated on every isInLandscapeMode toggle, causing React to detach/reattach the callback ref (old ref called with null, new ref called with the element). During this window the parent's composerRef is briefly null.

    Typing still works because character insertion is a simple IME append operation, but deletion requires a functioning InputConnection composing/batch-edit state which is broken after the rotation cycle.

    Notably, RNTextInputResetModule.resetKeyboardInput() — which calls imm.restartInput() to fix exactly this kind of IME desync — already exists in the codebase, but is only called when inserting emoji suggestions.

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

    Call RNTextInputReset.resetKeyboardInput(CONST.COMPOSER.NATIVE_ID) after orientation changes to re-establish the IME connection. The most natural place is in useLandscapeOnBlurProxy (index.android.ts) — after the 100ms refocus timeout fires, call resetKeyboardInput to restart the IME input connection. This mirrors the existing pattern used in SuggestionEmoji.

    Alternatively, the reset could be triggered in the native Composer's setTextInputRef callback when isInLandscapeMode changes, or via a useEffect watching isInLandscapeMode in ComposerWithSuggestions.

    What alternative solutions did you explore? (Optional)

    • Adding a key prop based on isInLandscapeMode to force a full remount of the RNMarkdownTextInput on orientation change — this would establish a clean IME connection but would lose the current text selection and cursor position, and is heavier than necessary.
    • Increasing ROTATION_REFOCUS_DELAY_MS — unlikely to help since the issue is the IME connection state, not timing of the focus call.

    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on May 13, 2026
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on May 13, 2026
  5. melvin-bot commented on May 13, 2026

    @melvin-bot

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

  6. changed the title [-][Exploratory] Chat - After switching to landscape mode, user can type on composer but is unable to delete.[/-] [+][$250] [Exploratory] Chat - After switching to landscape mode, user can type on composer but is unable to delete.[/+] on May 13, 2026
  7. melvin-bot commented on May 13, 2026

    @melvin-bot
  8. neerajbachani commented on May 13, 2026

    @neerajbachani
    Contributor

    Proposal

    What is the root cause of that problem?

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

    What alternative solutions did you explore? (Optional)

    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.

  9. github-actions commented on May 13, 2026

    @github-actions
    Contributor

    ⚠️ @neerajbachani Thanks for your proposal. Please update it to follow the proposal template, as proposals are only reviewed if they follow that format (note the mandatory sections).

  10. aswin-s commented on May 13, 2026

    @aswin-s
    Contributor

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

    On Android, after switching the device to landscape mode with the composer focused, users can continue typing new text but are unable to delete it using backspace. The typed characters appear locally in the IME but are never committed to the controlled input value, and any deletion attempt via backspace fails silently. Expected behavior is that both typing and deletion should work seamlessly across orientation changes.

    What is the root cause of that problem?

    The bug originates in src/hooks/useLandscapeOnBlurProxy/index.android.ts in the useLandscapeOnBlurProxy hook (lines 18–25). When the device rotates to landscape with the composer focused, the hook detects the orientation change and re-focuses the input after a 100ms delay to maintain focus across the transition. However, re-focusing the underlying ReactEditText does not re-establish the IME's InputConnection — character insertion still works because the IME continues appending text to the composing region, but InputConnection.deleteSurroundingText no longer reaches the native view, so backspace presses never fire onChangeText and the controlled input value immediately reverts any text the IME deleted locally.

    The codebase already contains the exact remedy: RNTextInputReset.resetKeyboardInput(nativeId) calls imm.restartInput() to re-establish a fresh InputConnection. This method is successfully used elsewhere in the codebase — specifically in src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions.tsx (lines 395–400) after emoji insertion — but it is not invoked after the orientation-triggered refocus in useLandscapeOnBlurProxy, leaving the InputConnection desynchronized.

    In ComposerWithSuggestions.tsx the module is obtained with const {RNTextInputReset} = NativeModules (imported from react-native), and access is guarded by a null-check before calling resetKeyboardInput. The same pattern must be applied in the hook.

    return (e) => {
    const isKeyboardOpening = isKeyboardAnimatingRef.current && isKeyboardActive;
    if ((prevIsInLandscapeMode !== isInLandscapeMode || isKeyboardOpening) && isInLandscapeMode) {
    setTimeout(() => inputRef.current?.focus?.(), ROTATION_REFOCUS_DELAY_MS);
    }
    onBlur?.(e);
    };
    };

    /** Focus the composer */
    focus: (shouldDelay?: boolean, forcedSelectionRange?: Selection, forceKeyboardIfAlreadyFocused?: boolean) => void;
    /** Replace the selection with text */
    replaceSelectionWithText: OnEmojiSelected;
    /** Get the current text of the composer */
    getCurrentText: () => string;
    /**
    * Calling clear will immediately clear the input on the UI thread (its a worklet).

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

    1. File: src/hooks/useLandscapeOnBlurProxy/index.android.ts
      Function: useLandscapeOnBlurProxy
      Description: Add NativeModules to the existing react-native import at the top of the file and destructure RNTextInputReset from it, matching the pattern already used in ComposerWithSuggestions.tsx. In the returned blur handler, after the orientation-triggered setTimeout that re-focuses the input, immediately call RNTextInputReset.resetKeyboardInput(CONST.COMPOSER.NATIVE_ID) inside the same callback — guarded by a null-check on RNTextInputReset in case the native module is unavailable (e.g. in test environments). This re-establishes the IME's InputConnection, allowing both character insertion and deletion to work correctly after landscape transitions.

      Because this change lives exclusively in index.android.ts (the other platform entry points — index.ts — return a no-op pass-through), the fix is automatically isolated to Android and cannot affect iOS or web builds.

      The resulting timeout callback becomes:

      setTimeout(() => {
          inputRef.current?.focus?.();
          if (RNTextInputReset) {
              RNTextInputReset.resetKeyboardInput(CONST.COMPOSER.NATIVE_ID);
          }
      }, ROTATION_REFOCUS_DELAY_MS);

      And the import block gains NativeModules:

      import {NativeModules} from 'react-native';
      
      const {RNTextInputReset} = NativeModules;

    Blast radius: Minimal. The change is localized to the landscape blur proxy hook and affects only the re-focus path triggered by orientation changes on Android. No other callers or workflows are modified.

    What alternative solutions did you explore? (Optional)

    N/A

  11. aswin-s commented on May 13, 2026

    @aswin-s
    Contributor

    Updated the proposal above to tighten 4 edge cases (additional guards and broader coverage).

  12. nabi-ebrahimi commented on May 13, 2026

    @nabi-ebrahimi

    Proposal

    What is the root cause of that problem?

    On Android, the landscape blur workaround refocuses the composer after a rotation-triggered blur, but it only calls focus() after the timeout and never restarts the Android IME input connection: https://github.com/Expensify/App/blob/bc9e4ab64f5e2bfe6da67b474273deec5d37dbfd/src/hooks/useLandscapeOnBlurProxy/index.android.ts#L18-L23

    After the portrait -> landscape -> portrait -> landscape sequence shown in the recording, the composer view is focused again and text insertion still reaches the field, but the keyboard’s deletion path is stale, so backspace does not update the controlled composer value.

    The app already has the native fix for this class of Android keyboard desync: RNTextInputReset.resetKeyboardInput() finds a view by native id and calls InputMethodManager.restartInput() on it: https://github.com/Expensify/App/blob/bc9e4ab64f5e2bfe6da67b474273deec5d37dbfd/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.kt#L19-L27

    That reset is only wired through the emoji suggestion flow today: https://github.com/Expensify/App/blob/bc9e4ab64f5e2bfe6da67b474273deec5d37dbfd/src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions.tsx#L395-L399 and https://github.com/Expensify/App/blob/bc9e4ab64f5e2bfe6da67b474273deec5d37dbfd/src/pages/inbox/report/ReportActionCompose/SuggestionEmoji.tsx#L85-L90

    The composer native input also sets id={CONST.COMPOSER.NATIVE_ID} but not nativeID, while the Android reset module searches by native id: https://github.com/Expensify/App/blob/bc9e4ab64f5e2bfe6da67b474273deec5d37dbfd/src/components/Composer/implementation/index.native.tsx#L123-L143

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

    Restart the Android IME input connection after the landscape refocus completes, and pass the actual input nativeID into the shared blur proxy instead of hard-coding the composer id inside the hook.

    Required changes:

    • Add nativeID={CONST.COMPOSER.NATIVE_ID} to the native composer input so RNTextInputResetModule can find the composer view.
    • Extend useLandscapeOnBlurProxy with an optional inputResetNativeID.
    • In index.android.ts, after the delayed focus() call, call RNTextInputReset.resetKeyboardInput(inputResetNativeID) when both the native module and native id are available.
    • Pass props.nativeID from RNMarkdownTextInput and RNTextInput into the hook.
    • Leave the non-Android hook as a pass-through, so web and iOS behavior stays unchanged.

    Tests that should be added or covered:

    • Android manual regression: open a chat, type in composer, rotate portrait/landscape as in the issue, keep typing, then verify backspace deletes the text.
    • Android manual regression for emoji suggestions: insert an emoji suggestion and verify keyboard/composer text stays in sync.
    • If hook tests are practical in the existing test setup, mock NativeModules.RNTextInputReset, timers, and the landscape state to verify the reset is called only when a native id is provided.

    Existing proposals identify the correct IME desync and the correct native reset API, but they put CONST.COMPOSER.NATIVE_ID directly inside the shared landscape blur hook. That leaves the hook resetting the composer even when another native text input triggers the landscape blur path, and it also misses that the reset module searches by nativeID, while the composer currently only sets id.

    I also considered forcing a composer remount on orientation changes, but that is heavier and risks losing selection/caret state. Increasing the refocus delay only changes timing and does not restart the stale Android InputConnection.

    What alternative solutions did you explore? (Optional)

  13. github-actions commented on May 13, 2026

    @github-actions
    Contributor

    ⚠️ @nabi-ebrahimi Thanks for your proposal. Please update it to follow the proposal template, as proposals are only reviewed if they follow that format (note the mandatory sections).

  14. oqildev commented on May 13, 2026

    @oqildev
    Contributor

    Proposal

    What is the root cause of that problem?

    I traced this to an Android-only IME desync left behind by the rotation refocus workaround.

    When the user does portrait → landscape → portrait → landscape with the composer focused, the second flip into landscape fires a native blur on the underlying ReactEditText. useLandscapeOnBlurProxy catches that blur and re-focuses the input after a 100ms delay so the keyboard pops back up:

    const useLandscapeOnBlurProxy: UseLandscapeOnBlurProxy = (inputRef, onBlur) => {
    const isInLandscapeMode = useIsInLandscapeMode();
    const prevIsInLandscapeMode = usePrevious(isInLandscapeMode);
    return (e) => {
    if (prevIsInLandscapeMode !== isInLandscapeMode && isInLandscapeMode) {
    setTimeout(() => inputRef.current?.focus?.(), ROTATION_REFOCUS_DELAY_MS);
    }
    onBlur?.(e);
    };
    };

    The problem is that View.requestFocus() on its own does not rebuild the IME's InputConnection. After the blur/refocus cycle, the IME on a lot of Android keyboards (Gboard / Motorola stock are the classic offenders) keeps editing into a stale, half-detached InputConnection:

    • New characters still arrive on the JS side — Android keyboards fall back to dispatching plain KEY_DOWN events for printable characters when the connection is degraded, so onChangeText keeps firing and the controlled value keeps growing.
    • KEYCODE_DEL / backspace, however, is delivered through InputConnection.deleteSurroundingText / setComposingRegion on the stale connection. Those calls never reach the live ReactEditText, so onChangeText never fires, and the controlled value immediately re-renders whatever the IME tried to delete locally — which looks exactly like "delete does nothing".

    The codebase already has the standard remedy for this Android-IME-restart class of bug. RNTextInputResetModule.resetKeyboardInput calls InputMethodManager.restartInput() on the view with the matching native id:

    @ReactMethod
    fun resetKeyboardInput(nativeId: String) {
    reactContext.runOnUiQueueThread {
    val imm = reactApplicationContext.baseContext.getSystemService(
    Context.INPUT_METHOD_SERVICE
    ) as? InputMethodManager
    val reactNativeView = reactApplicationContext.getCurrentActivity()?.findViewById<View>(android.R.id.content)
    val viewToReset = reactNativeView?.let { ReactFindViewUtil.findView(it, nativeId) }
    imm?.restartInput(viewToReset)
    }
    }

    …and we already wire it up successfully for the very similar emoji-suggestion case where the IME's composing region also goes stale:

    const resetKeyboardInput = useCallback(() => {
    if (!RNTextInputReset) {
    return;
    }
    RNTextInputReset.resetKeyboardInput(CONST.COMPOSER.NATIVE_ID);
    }, []);

    It is simply not being called from the rotation path in useLandscapeOnBlurProxy/index.android.ts. The composer input is already tagged with id={CONST.COMPOSER.NATIVE_ID} (which RN maps to the Android native id), so ReactFindViewUtil.findView can find it:

    return (
    <RNMarkdownTextInput
    id={CONST.COMPOSER.NATIVE_ID}
    multiline
    autoComplete="off"
    placeholderTextColor={theme.placeholderText}
    ref={setTextInputRef}
    value={value}
    rejectResponderTermination={false}
    smartInsertDelete={false}
    textAlignVertical="center"
    style={[composerStyle, maxHeightStyle]}
    markdownStyle={markdownStyle}
    /* eslint-disable-next-line react/jsx-props-no-spreading */
    {...props}
    autoFocus={isInLandscapeMode ? false : props.autoFocus}
    readOnly={isDisabled}
    onPaste={pasteFile}
    onClear={onClear}
    disableFullscreenUI
    />
    );

    Alternative I ruled out

    I first suspected the focus() no-op proxy in getLandscapeTextInputRefProxy:

    function getLandscapeTextInputRefProxy(textInputRef: AnimatedMarkdownTextInputRef | BaseTextInputRef | null): AnimatedMarkdownTextInputRef | BaseTextInputRef | null {
    return textInputRef
    ? new Proxy(textInputRef, {
    get(target, prop, receiver) {
    if (prop !== 'focus') {
    // eslint-disable-next-line @typescript-eslint/no-unsafe-return
    return Reflect.get(target, prop, receiver);
    }
    return () => {};
    },
    })
    : textInputRef;
    }

    Rejected: the proxy only wraps the external ref handed to the parent (Composer/implementation/index.native.tsx line 74). The inputRef passed into useLandscapeOnBlurProxy is the local useRef inside RNMarkdownTextInput.tsx (line 35) and RNTextInput.tsx (line 23) — both raw, not proxied. So the post-rotation inputRef.current?.focus?.() call genuinely runs and focus is restored. The symptom isn't "no focus", it's "focus restored but IME connection is stale".

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

    Fix it in the same layer that already owns the rotation workaround: useLandscapeOnBlurProxy/index.android.ts. After the existing setTimeout re-focuses the input, on the same tick, call RNTextInputReset.resetKeyboardInput(...) with the input's native id. That forces imm.restartInput() against the live ReactEditText, which is exactly what's needed to drop the stale InputConnection and rebind a fresh one. Backspace then routes through the new connection and onChangeText fires normally.

    Concretely:

    1. In useLandscapeOnBlurProxy/index.android.ts, inside the setTimeout callback, after inputRef.current?.focus?.(), call NativeModules.RNTextInputReset?.resetKeyboardInput(nativeID). Guard with the RNTextInputReset null check used in ComposerWithSuggestions.tsx (line 329) so we don't crash if the module isn't registered (e.g. tests, future Mobile-Expensify hybrid swap).
    2. Plumb the input's native id into the hook rather than hardcoding CONST.COMPOSER.NATIVE_ID. Extend UseLandscapeOnBlurProxy in src/hooks/useLandscapeOnBlurProxy/types.ts with a third arg (e.g. nativeID?: string), and pass props.nativeID ?? props.id from RNMarkdownTextInput.tsx:40 and RNTextInput.tsx:24. The hook is also consumed by RNTextInput, so a hardcoded composer id would (a) wrongly reset the wrong view on non-composer inputs and (b) silently no-op when nativeID isn't set.
    3. Bail out early if the resolved nativeID is undefined — ReactFindViewUtil.findView(root, null) would call restartInput(null), which restarts the IME against the currently focused view; harmless here, but worth being explicit.
    4. Leave the web/iOS pass-through (src/hooks/useLandscapeOnBlurProxy/index.ts) unchanged — iOS doesn't lose focus on rotation and RNTextInputReset is Android-only.
    5. Keep the existing 100ms refocus delay; the IME restart must run after the focus call, otherwise restartInput has no focused view to attach to.

    Edge cases worth covering:

    • Composer is empty when the rotation completes: harmless — restart + empty value just rebinds a fresh connection.
    • User has an emoji suggestion popup open during rotation: the existing resetKeyboardInput after emoji insertion still runs independently; both paths target the same view by native id, so they don't conflict.
    • Offline / queued comment drafts: the fix is purely local to the input view; no Onyx writes involved, so offline behavior is unaffected.

    What alternative solutions did you explore? (Optional)

    • Drop the rotation refocus entirely. Rejected: that re-introduces the bug PR Fix Different typing mode when rotating device from portrait to landscape #87338 was intended to address (composer loses focus on rotate-to-landscape).
    • Switch the composer to an uncontrolled value on Android. Rejected: the controlled value is load-bearing for draft saving, mention parsing, markdown rendering, and RNMarkdownTextInput's parser worklet — all of which read props.value.
    • Blur-then-focus instead of just focus inside the timeout. Rejected: imm.restartInput() is the documented fix for stale InputConnection; a JS-side blur/focus cycle relies on RN's TextInput bridging to do the right thing on its own, which is exactly what's failing here.
    • Toggle key on the input to force remount on rotation. Rejected: remounting tears down the markdown parser, scroll position, selection state, and any in-flight IME composition — a sledgehammer for a problem the existing native module already solves cleanly.
  15. github-actions commented on May 13, 2026

    @github-actions
    Contributor

    ⚠️ @oqildev Thanks for your proposal. Please update it to follow the proposal template, as proposals are only reviewed if they follow that format (note the mandatory sections).

  16. abzokhattab commented on May 17, 2026

    @abzokhattab
    Contributor

    Unable to reproduce the issue following the steps. Could you please recheck @jponikarchuk

    Screen.Recording.2026-05-18.at.00.23.48.mov
  17. jponikarchuk commented on May 18, 2026

    @jponikarchuk
    Author

    @abzokhattab The issue is not reproducible now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions