You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Chat - Website crashes after deleting a comment #85424
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
👋 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:
Identify the pull request that introduced this issue and revert it.
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
The bug is reproducible on staging (v9.3.38-0) but not production, indicating it was introduced in this deploy cycle
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:
constsetTextInputRef=useCallback((el: TextInput)=>{if(isFocused){// <-- New condition addedReportActionComposeFocusManager.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:
User presses Arrow Up to edit a message (edit composer opens, main composer loses focus)
The main composer's composerRef.current is not updated due to the isFocused check
User deletes content and presses Enter
Code elsewhere attempts to access composerRef.current expecting it to be valid
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:
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:
constsetTextInputRef=useCallback((el: TextInput)=>{if(isFocused){// <-- new guardReportActionComposeFocusManager.composerRef.current=el;}textInputRef.current=el;
...
},[animatedRef,isFocused],// <-- isFocused added);
This causes two problems:
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 useImperativeHandleauto-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).
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)
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.
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.
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
@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.
Activity
github-actions commentedon Mar 16, 2026
👋 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:
melvin-bot commentedon Mar 16, 2026
You have been assigned to this deploy blocker because you recently merged this PR: #83824
melvin-bot commentedon Mar 16, 2026
💬 A slack conversation has been started in #expensify-open-source
OSBotify commentedon Mar 16, 2026
🔍 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
DeployBlockerCashlabel as appropriate. No label changes needed.📋 Detailed Analysis
Evidence
Verification
src/pages/inbox/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsxif (isFocused)condition at line 317 before settingReportActionComposeFocusManager.composerRef.current = elRoot Cause
The PR modified the
setTextInputRefcallback to only updateReportActionComposeFocusManager.composerRef.currentwhenisFocusedis true:The problem: When the main composer loses focus (e.g., when edit composer opens), the
composerRef.currentis no longer updated. This creates a scenario where:composerRef.currentis not updated due to theisFocusedcheckcomposerRef.currentexpecting it to be validAdditionally, there's an inconsistency: Line 759 in the same file still sets the ref unconditionally:
This inconsistency between conditional and unconditional ref updates creates unpredictable behavior.
MelvinBot commentedon Mar 16, 2026
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
isFocusedguard to thesetTextInputRefcallback inComposerWithSuggestions.tsxand addedisFocusedto theuseCallbackdependency array:This causes two problems:
Ref callback identity changes on focus change. Adding
isFocusedto deps meanssetTextInputRefgets a new function identity whenever screen focus changes. React 19'suseImperativeHandleauto-appends the ref to its own deps, so whensetTextInputRefchanges identity, the imperative handle layout effect re-runs — calling the old callback withnull(which setscomposerRef.current = nullsince the old closure hadisFocused=true), then calling the new callback with the element (which does NOT restorecomposerRef.currentbecause the guardif(isFocused)fails whenisFocused=false).Cascading focus/scroll race condition during delete. With
composerRef.currentstale/null,ReportActionComposeFocusManager.isFocused()returns false. When the delete confirmation modal closes, theFocusTrapForModal'ssetReturnFocus(index.web.tsx:19-22) seesisFocused()=falseand attempts to return focus to the pre-modal element (the now-unmounted edit composer). This, combined withdeleteDrafttriggeringscrollToIndex(0)(ReportActionItemMessageEdit.tsx:296-298), creates a timing condition where theInvertedFlatList's underlyingVirtualizedListcrashes with:This occurs because the list data shrinks from 2 items to 1 (the optimistic
DeleteCommentremoves the message), but the VirtualizedList's internalcellsAroundViewportstate{first: 0, last: 1}hasn't been constrained before_createRenderMaskruns. The invariantcellsAroundViewport.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
setTextInputRefinComposerWithSuggestions.tsx. Specifically, remove theif (isFocused)guard and removeisFocusedfrom the dependency array, restoring the unconditionalReportActionComposeFocusManager.composerRef.current = elassignment.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
isFocusedto the ref callback's dependencies. One alternative is to use auseRefto track theisFocusedvalue 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)
Use a ref for isFocused instead of a dependency — store
isFocusedin auseRefand readisFocusedRef.currentinsidesetTextInputRefwithout adding it to the deps array. This preserves the callback identity (avoiding the React ref lifecycle cascade) while still gatingcomposerRef.currentupdates. However, this may still leavecomposerRef.currentstale 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.Add null safety in
_createRenderMaskcallers — 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 thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.madmax330 commentedon Mar 16, 2026
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
QichenZhu commentedon Mar 16, 2026
@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
1 remaining item
M00rish commentedon Mar 16, 2026
@QichenZhu, not related as i can't reproduce on the adhbuild for my PR :
https://83824.pr-testing.expensify.com
cristipaval commentedon Mar 17, 2026
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.
QichenZhu commentedon Mar 17, 2026
@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.
M00rish commentedon Mar 17, 2026
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
IuliiaHerets commentedon Mar 17, 2026
Chrome / v9.3.38-1 PR:85511
Passed
Screen.Recording.2026-03-17.at.10.38.13.mp4
IuliiaHerets commentedon Mar 17, 2026
9.3.38-2
Reproduced
Screen.Recording.2026-03-17.at.10.45.43.mp4
M00rish commentedon Mar 17, 2026
@IuliiaHerets would you able to test : #85366 adhoc build too ? thanks
cristipaval commentedon Mar 17, 2026
Asked for a retest here after CP'ing #85366
If it still reproduces, I'll proceed with reverting #83824
izarutskaya commentedon Mar 17, 2026
It is passed
Chrome
Build 9.3.38-3
Screen.Recording.2026-03-17.at.11.31.26.mp4
Recording.3675.mp4
cristipaval commentedon Mar 17, 2026
Great! Thank you all, closing it.