Skip to content

[$250] Not able to focus on main composer while edit composer is open #79769

Closed

Description

@aimane-chnaif

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.3.2-2
Reproducible in staging?: Y
Reproducible in production?: Y
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: @aimane-chnaif
Slack conversation (hyperlinked to channel name):

Action Performed:

  1. Go to any chat and send any message
  2. Focus on composer
  3. Press Up Arrow to edit message
  4. Switch to another chat and come back
  5. Focus on edit composer
  6. Focus on main composer

Expected Result:

Main composer should be focused

Actual Result:

Main composer is focused briefly, and then edit composer is focused back

Workaround:

Close edit composer to be able to focus back on main composer

Platforms:

Select the officially supported platforms where the issue was reproduced:

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

Screenshots/Videos

bug.mov

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022013509624834775039
  • Upwork Job ID: 2013509624834775039
  • Last Price Increase: 2026-02-17
Issue OwnerCurrent Issue Owner: @madmax330

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jan 16, 2026
  2. melvin-bot commented on Jan 16, 2026

    @melvin-bot

    Triggered auto assignment to @greg-schroeder (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. annaweber830 commented on Jan 16, 2026

    @annaweber830
    Contributor

    Proposal

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

    When the edit composer is open, the user can’t reliably focus the main composer. The main composer receives focus briefly, then focus snaps back to the edit composer—especially after switching chats and returning.

    What is the root cause of that problem?

    Our focus-management behavior includes automatic refocusing intended to keep editing stable (e.g., restoring the last focused composer / maintaining edit state across navigation). In this scenario, that auto-refocus logic can run after the user explicitly focuses the main composer, causing the edit composer to steal focus back.
    Concretely, a delayed “restore focus” (triggered by blur/navigation/interaction completion) doesn’t distinguish between:

    • “Edit composer lost focus unintentionally, restore it”
    • “User intentionally focused a different input (main composer), do not override”

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

    • Update composer focus restoration logic to be non-invasive:
      • If another text input is already focused (e.g., the main composer), do not refocus the edit composer.
      • If a delayed refocus is scheduled, re-check what is currently focused right before applying focus, and cancel if focus has moved elsewhere.
        Ensure the “last focused composer should regain focus” rule only applies when focus was lost due to non-user-intentional causes (e.g., transient UI events), not when the user explicitly taps/focuses the main composer.
        if (!isFocused && !onyxFocused && !modal.willAlertModalBecomeVisible && !modal.isVisible && refSave) {
        if (!ReportActionComposeFocusManager.isFocused()) {
        // Focusing will fail when it is called immediately after closing modal so we call it after interaction.
        // eslint-disable-next-line @typescript-eslint/no-deprecated
        InteractionManager.runAfterInteractions(() => {
        refSave?.focus();
        });
        } else {
        refSave = undefined;
        }
        }
    if (!isFocused && !onyxFocused && !modal.willAlertModalBecomeVisible && !modal.isVisible && refSave) {
            const activeElement = DomUtils.getActiveElement();
            const isAnotherTextInputFocused =
                !!activeElement && activeElement !== refSave && (activeElement.nodeName === 'INPUT' || activeElement.nodeName === 'TEXTAREA');
    
            if (isAnotherTextInputFocused) {
                refSave = undefined;
                return;
            }
    
            // Focusing will fail when it is called immediately after closing modal so we call it after interaction.
            // eslint-disable-next-line @typescript-eslint/no-deprecated
            InteractionManager.runAfterInteractions(() => {
                // Re-check after interactions: focus may have moved to another input by the time this runs.
                if (ReportActionComposeFocusManager.isFocused()) {
                    refSave = undefined;
                    return;
                }
    
                const currentActiveElement = DomUtils.getActiveElement();
                const isTextInputCurrentlyFocused =
                    !!currentActiveElement && currentActiveElement !== refSave && (currentActiveElement.nodeName === 'INPUT' || currentActiveElement.nodeName === 'TEXTAREA');
                if (isTextInputCurrentlyFocused) {
                    refSave = undefined;
                    return;
                }
    
                refSave?.focus();
            });
        }
    

    What alternative solutions did you explore? (Optional)

  4. yatin-italy commented on Jan 16, 2026

    @yatin-italy

    Proposal

    Restate the problem this issue is trying to solve.

    • When the edit composer is open, the user clicks the main composer.
    • The main composer gets focus for a moment.
    • Then the edit composer takes focus back.
    • The user cannot type a new message.

    What is the root cause of that problem?

    • The edit composer schedules a delayed refocus after blur.
    • It assumes no other composer will get focus.
    • If the user clicks the main composer before the callback runs, the callback still fires.
    • This steals focus back to the edit composer.

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

    • Enforce one rule.
    • Never refocus the edit composer if another composer is focused.
    • Add a check inside the delayed callback.
    • If a composer is already focused, exit and clear the ref.
    • Apply the same logic on desktop and website.

    index.desktop.ts
    Lines 20-32

        if (!isFocused && !onyxFocused && !modal.willAlertModalBecomeVisible && !modal.isVisible && refSave) {
    -        if (!ReportActionComposeFocusManager.isFocused()) {
    -            InteractionManager.runAfterInteractions(() => {
    -                refSave?.focus();
    -            });
    -        } else {
    -            refSave = undefined;
    -        }
    +        InteractionManager.runAfterInteractions(() => {
    +            if (ReportActionComposeFocusManager.isFocused()) {
    +                refSave = undefined;
    +                return;
    +            }
    +            refSave?.focus();
    +        });
        }
    

    index.website.ts
    Lines 20-32

        if (!isFocused && !onyxFocused && !modal.willAlertModalBecomeVisible && !modal.isVisible && refSave) {
    -        if (!ReportActionComposeFocusManager.isFocused()) {
    -            InteractionManager.runAfterInteractions(() => {
    -                refSave?.focus();
    -            });
    -        } else {
    -            refSave = undefined;
    -        }
    +        InteractionManager.runAfterInteractions(() => {
    +            if (ReportActionComposeFocusManager.isFocused()) {
    +                refSave = undefined;
    +                return;
    +            }
    +            refSave?.focus();
    +        });
        }
    

    What alternative solutions did you explore? (Optional)

  5. aimane-chnaif commented on Jan 16, 2026

    @aimane-chnaif
    ContributorAuthor

    @greg-schroeder Please assign @blazejkustra and me here. This is coming from #79359 (comment)

  6. melvin-bot commented on Jan 20, 2026

    @melvin-bot

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

  7. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jan 20, 2026
  8. changed the title [-]Not able to focus on main composer while edit composer is open[/-] [+][$250] Not able to focus on main composer while edit composer is open[/+] on Jan 20, 2026
  9. melvin-bot commented on Jan 20, 2026

    @melvin-bot
  10. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jan 20, 2026
  11. melvin-bot commented on Jan 20, 2026

    @melvin-bot

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

  12. 62 remaining items

  13. QichenZhu commented on Mar 7, 2026

    @QichenZhu
    Contributor

    had an issue with ios app posted on slack for help

    How's it going? @M00rish

  14. M00rish commented on Mar 9, 2026

    @M00rish
    Contributor

    still investigating ios build crash after login with this error :

    [javascript] [TypeError: Assertion failed: `SortCompare` must be an abstract closure taking 2 arguments]
    Unhandled JS Exception: TypeError: Assertion failed: `SortCompare` must be an abstract closure taking 2 arguments
    

    @QichenZhu

  15. M00rish commented on Mar 10, 2026

    @M00rish
    Contributor

    issue solved and PR opened for review

  16. M00rish commented on Mar 11, 2026

    @M00rish
    Contributor

    @QichenZhu friendly bump.

  17. melvin-bot commented on Mar 16, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  18. M00rish commented on Mar 24, 2026

    @M00rish
    Contributor

    @greg-schroeder could you please process payment here ? Thanks.

    Note: there's no regressions.

  19. greg-schroeder commented on Mar 24, 2026

    @greg-schroeder
    Contributor

    Payment summary:

    Author: @M00rish - $250 - Offer sent via Upwork
    Reviewer: @QichenZhu - $250 - ND manual request

    Approved for payments as outlined above ☝️

  20. QichenZhu commented on Mar 24, 2026

    @QichenZhu
    Contributor

    BugZero Checklist:

    • [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: Refactor createTaskAndNavigate() to use useAncestors hook  #73867 (comment)

    • [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: N/A.

    • [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.

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

    Regression Test Proposal

    Test:

    1. Clear the Onyx cache
    2. Go to any chat and send a message
    3. Focus on the Composer
    4. Press the Up Arrow to edit the message
    5. Switch to another chat and then come back
    6. Focus on the edit Composer
    7. Focus on the main Composer
    8. Verify the focus stays on the main Composer and does not jump to the edit Composer

    Do we agree 👍 or 👎

  21. twisterdotcom commented on Mar 24, 2026

    @twisterdotcom
    Contributor

    @QichenZhu has submitted payment for this report on ND here.

    SO: https://stackoverflowteams.com/c/expensify/questions/7582

    Zapier Logs Run ID: 00040eee-5039-a9ed-11d3-d1f7b9d5aeb4
  22. M00rish commented on Mar 25, 2026

    @M00rish
    Contributor

    Offer accepted @greg-schroeder.

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions