Skip to content

Chat - Website crashes after deleting a comment #85424

Closed

Description

@lanitochka17

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.38-0
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #83824
Email or phone of affected tester (no customers): biruknew45+66yyjjj@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Critical User Impact
Device used: Web
App Component: Chat Report View

Action Performed:

  1. https://staging.new.expensify.com
  2. Go to new chat (new WS chat or user)
  3. Send any message
  4. Press Arrow Up key on keyboard
  5. Select All - Ctrl / Cmd + A
  6. Press 'Delete' key
  7. Press 'Enter' key
  8. Click "Enter" key to confirm

Expected Result:

it shouldn't crash

Actual Result:

website crashes

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7104313_1773674279568.bandicam_2026-03-16_18-00-46-843.mp4

Bug7104313_1773674279576!staging.new.expensify.com-1773674246256.txt

View all open jobs on GitHub

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 16, 2026
  2. github-actions commented on Mar 16, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  3. melvin-bot commented on Mar 16, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #83824

  4. melvin-bot commented on Mar 16, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  5. OSBotify commented on Mar 16, 2026

    @OSBotify
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #83824 - "Fix : Not able to focus on main composer while edit composer is open." by @M00rish (High confidence)
    Related Issues: #79769

    Recommendation: REVERT

    PR #83824 introduced a conditional check that prevents the main composer ref from being updated when the composer loses focus. This causes crashes when code attempts to access the now-stale or null composer reference, particularly during the delete-comment-and-confirm flow described in the reproduction steps.

    Labels: This is a frontend bug caused by an App PR. Keeping DeployBlockerCash label as appropriate. No label changes needed.

    📋 Detailed Analysis

    Evidence

    Verification

    • Affected file: src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx
    • The change: Added if (isFocused) condition at line 317 before setting ReportActionComposeFocusManager.composerRef.current = el
    • Confirmed: This is the exact file that handles composer focus management and edit functionality

    Root Cause

    The PR modified the setTextInputRef callback to only update ReportActionComposeFocusManager.composerRef.current when isFocused is true:

    const setTextInputRef = useCallback(
        (el: TextInput) => {
            if (isFocused) {  // <-- New condition added
                ReportActionComposeFocusManager.composerRef.current = el;
            }
            textInputRef.current = el;
            // ...
        },
        [animatedRef, isFocused],
    );

    The problem: When the main composer loses focus (e.g., when edit composer opens), the composerRef.current is no longer updated. This creates a scenario where:

    1. User presses Arrow Up to edit a message (edit composer opens, main composer loses focus)
    2. The main composer's composerRef.current is not updated due to the isFocused check
    3. User deletes content and presses Enter
    4. Code elsewhere attempts to access composerRef.current expecting it to be valid
    5. The ref is now stale/null, causing a crash

    Additionally, there's an inconsistency: Line 759 in the same file still sets the ref unconditionally:

    ReportActionComposeFocusManager.composerRef.current = textInputRef.current;

    This inconsistency between conditional and unconditional ref updates creates unpredictable behavior.

  6. MelvinBot commented on Mar 16, 2026

    @MelvinBot
    Contributor

    Proposal

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

    The website crashes (shows error boundary page) after the user: (1) sends a message, (2) presses Arrow Up to edit it, (3) selects all text with Ctrl+A and deletes it, (4) presses Enter and confirms deletion. This is a regression introduced in v9.3.38-0 — reproducible on staging but not production.

    What is the root cause of that problem?

    PR #83824 added an isFocused guard to the setTextInputRef callback in ComposerWithSuggestions.tsx and added isFocused to the useCallback dependency array:

    const setTextInputRef = useCallback(
        (el: TextInput) => {
            if (isFocused) {  // <-- new guard
                ReportActionComposeFocusManager.composerRef.current = el;
            }
            textInputRef.current = el;
            ...
        },
        [animatedRef, isFocused],  // <-- isFocused added
    );

    This causes two problems:

    1. Ref callback identity changes on focus change. Adding isFocused to deps means setTextInputRef gets a new function identity whenever screen focus changes. React 19's useImperativeHandle auto-appends the ref to its own deps, so when setTextInputRef changes identity, the imperative handle layout effect re-runs — calling the old callback with null (which sets composerRef.current = null since the old closure had isFocused=true), then calling the new callback with the element (which does NOT restore composerRef.current because the guard if(isFocused) fails when isFocused=false).

    2. Cascading focus/scroll race condition during delete. With composerRef.current stale/null, ReportActionComposeFocusManager.isFocused() returns false. When the delete confirmation modal closes, the FocusTrapForModal's setReturnFocus (index.web.tsx:19-22) sees isFocused()=false and attempts to return focus to the pre-modal element (the now-unmounted edit composer). This, combined with deleteDraft triggering scrollToIndex(0) (ReportActionItemMessageEdit.tsx:296-298), creates a timing condition where the InvertedFlatList's underlying VirtualizedList crashes with:

      Invariant Violation: Invalid cells around viewport "[0, 1]" was passed to VirtualizedList._createRenderMask
      

      This occurs because the list data shrinks from 2 items to 1 (the optimistic DeleteComment removes the message), but the VirtualizedList's internal cellsAroundViewport state {first: 0, last: 1} hasn't been constrained before _createRenderMask runs. The invariant cellsAroundViewport.last < itemCount (i.e., 1 < 1) fails.

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

    Revert PR #83824's change to setTextInputRef in ComposerWithSuggestions.tsx. Specifically, remove the if (isFocused) guard and remove isFocused from the dependency array, restoring the unconditional ReportActionComposeFocusManager.composerRef.current = el assignment.

    The original issue that PR #83824 addressed (#79769 — not able to focus main composer while edit composer is open) should be solved with a different approach that does not add isFocused to the ref callback's dependencies. One alternative is to use a useRef to track the isFocused value and read from the ref inside the callback, preserving callback identity and avoiding React's ref lifecycle re-triggering.

    What alternative solutions did you explore? (Optional)

    1. Use a ref for isFocused instead of a dependency — store isFocused in a useRef and read isFocusedRef.current inside setTextInputRef without adding it to the deps array. This preserves the callback identity (avoiding the React ref lifecycle cascade) while still gating composerRef.current updates. However, this may still leave composerRef.current stale when the composer is unfocused, so the original issue ([$250] Not able to focus on main composer while edit composer is open #79769) would need careful re-evaluation to find the real fix.

    2. Add null safety in _createRenderMask callers — this would be a workaround at the VirtualizedList level, which isn't the right layer to fix since the root cause is in the app's focus management.


    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.

  7. madmax330 commented on Mar 16, 2026

    @madmax330
    Contributor

    Melvin's proposal sounds good to me since he found an offending PR. I think this is big enough of a regression that we should revert instead of moving forward, but leaving it up to @cristipaval to decide

  8. QichenZhu commented on Mar 16, 2026

    @QichenZhu
    Contributor

    @MelvinBot, I tested reverting #83824 locally but it didn't fix this issue.

    Hi @M00rish, can you try reverting on your end?

    cc @madmax330 @cristipaval

  9. 1 remaining item

  10. M00rish commented on Mar 16, 2026

    @M00rish
    Contributor

    @QichenZhu, not related as i can't reproduce on the adhbuild for my PR :
    https://83824.pr-testing.expensify.com

  11. self-assigned this
    on Mar 17, 2026
  12. cristipaval commented on Mar 17, 2026

    @cristipaval
    Contributor

    Opened a draft PR with the revert of #83824 and asked Applause to retest on the adhoc build, here.
    Also asked to retest on the latest staging.

  13. QichenZhu commented on Mar 17, 2026

    @QichenZhu
    Contributor

    @cristipaval just a suggestion, maybe also test the adhoc build for the revert of #82507 since the revert has been merged on main but not CPed to staging.

  14. M00rish commented on Mar 17, 2026

    @M00rish
    Contributor

    agreed, i tested that revert and it fixed it

    also mine #83824 was merged 1 day before #82507, so it never had the bug

    @cristipaval

  15. IuliiaHerets commented on Mar 17, 2026

    @IuliiaHerets

    Chrome / v9.3.38-1 PR:85511
    Passed

    Screen.Recording.2026-03-17.at.10.38.13.mp4
  16. IuliiaHerets commented on Mar 17, 2026

    @IuliiaHerets

    9.3.38-2
    Reproduced

    Screen.Recording.2026-03-17.at.10.45.43.mp4
  17. M00rish commented on Mar 17, 2026

    @M00rish
    Contributor

    @IuliiaHerets would you able to test : #85366 adhoc build too ? thanks

  18. cristipaval commented on Mar 17, 2026

    @cristipaval
    Contributor

    Asked for a retest here after CP'ing #85366

    If it still reproduces, I'll proceed with reverting #83824

  19. izarutskaya commented on Mar 17, 2026

    @izarutskaya

    It is passed
    Chrome
    Build 9.3.38-3

    Screen.Recording.2026-03-17.at.11.31.26.mp4
    Recording.3675.mp4
  20. cristipaval commented on Mar 17, 2026

    @cristipaval
    Contributor

    Great! Thank you all, closing it.

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.EngineeringHourlyKSv2ReviewingHas a PR in review

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions