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
[Due for payment 2026-08-05] [$250] Chat - Conversation shows a new message marker after being viewed #95871
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Version Number: 9.4.33-1 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack:https://test-management.browserstack.com/projects/2219752/test-runs/64161031/folder/13176910/41237477/1558640174?sort=%2Bidentifier Email or phone of affected tester (no customers): n/a Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: Mac 15.4.1 Safari, Chrome, iPhone 13 iOS 26.5 App Component: Chat Report View
Navigate to the conversation with the secondary user. Be sure to clear any unread messages if needed
Keep the conversation in view of the most recent message
As the secondary user - Send some messages to the main user
Expected Result:
The chat should remain read, and no new message marker should be displayed after reopening the conversation if the message was already viewed
Actual Result:
When a new message is received while the user is viewing the conversation, the chat is marked as unread in LHN. After leaving and reopening the conversation, the new message marker is displayed even though the message has already been viewed
The "new message" marker and the LHN unread state are both driven by report.lastReadTime. On (re)open, useUnreadMarker seeds the marker time from report.lastReadTime, and a message shows the marker whenever lastReadTime < message.created (isReportActionUnread).
lastReadTime is only advanced by readNewestAction. When a message arrives while you're viewing the chat, the auto-mark-as-read in useMarkAsRead is gated:
If that gate is false, readNewestAction is skipped, readActionSkippedRef is set, and lastReadTime is never advanced. The only recovery (completeSkippedMarkAsRead) requires the unread marker to scroll back into view while focused — so if the user leaves first, lastReadTime stays stale. On reopen the marker is re-seeded from that stale value and reappears over an already-viewed message. The LHN staying unread is consistent with lastReadTime never advancing.
The gate's isScrolledToEnd term (= !hasScrolledOverThreshold, a 250px threshold — ReportActionsList.tsx:195) is the most likely culprit. hasScrolledOverThreshold is state that is only updated by onScroll (ReportActionsList.tsx:294-297). If the user scrolled up (loading history / glancing back) and returned to the bottom via a programmaticscrollToBottom (a non-animated scrollToIndex) that doesn't emit a settling onScroll, hasScrolledOverThreshold stays stale-true even though the user is visually at the newest message — so the next inbound message hits the failing branch.
Why "at the bottom" can still fail: the list is inverted (bottom ≈ offset 0), so appending a message does not spike the offset. hasScrolledOverThreshold and the pin-to-bottom scrollOffsetRef (useScrollToEndOnNewMessageReceived.ts:65-82) are both only updated by onScroll, so a programmatic return-to-bottom that doesn't emit onScroll leaves them stale-high.
Alternatives considered: stale closure in the effect (ruled out — the gate runs inside a useEffectEvent, always current); hasNewerActions true while at the live tail (ruled out for this repro — it's hasPreviousPage, false when viewing the newest message); isVisible/Visibility.hasFocus() momentarily false (possible secondary trigger).
Confidence: High on the mechanism (stale lastReadTime → marker on reopen). Medium on the exact sub-trigger — runtime logging of isScrolledToEnd/scrollOffsetRef/contentOffset.y at the moment handleReportChangeMarkAsRead runs would pin it down. No accountID/reportID in the report to scope a production log query.
What changes do you think we should make in order to solve the problem?
Make read-state robust to a stale scroll gate so lastReadTime advances whenever a message is genuinely viewed:
Primary: When the list is programmatically scrolled to the bottom, reset hasScrolledOverThreshold (and the scrollOffsetRef used by the pin-to-bottom logic) to their below-threshold values, instead of waiting for an onScroll that may never fire — so isScrolledToEnd reflects reality.
Defense-in-depth: Complete the deferred readActionSkippedRef when the report is visible + focused and the newest action is rendered, rather than only when the unread marker scrolls into view — so leaving the chat doesn't strand a skipped mark-as-read.
What alternative solutions did you explore? (Optional)
Emitting onScroll (or its state update) after every programmatic scrollToBottom; and re-running the mark-as-read gate on report blur/unmount when the newest action is on screen.
Next Steps for Contributor+ team: To accept:@MelvinBot implement [this](https://github.com/Expensify/App/issues/95871) to create a draft PR. To refine:@MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.
Please re-state the problem that we are trying to solve in this issue.
When a new message arrives while I have the conversation open, scrolled to the latest message, and visible on screen — but the browser window does not hold OS focus (e.g. focus is on another window/tab) — the report is marked unread in the LHN, and after leaving and reopening the conversation a "New" message marker is shown above a message I already saw.
What is the root cause of that problem?
The read logic uses Visibility.hasFocus() (OS window focus) as the proxy for "the user has viewed this message." But a conversation can be fully visible on screen and scrolled to the newest message without the window holding OS focus — which is exactly what happens in the repro, where the same tester keeps the main user's conversation in view while sending from the secondary user's window (that second window takes OS focus).
When a new action lands, handleReportChangeMarkAsRead decides whether to mark the report read, and it requires Visibility.hasFocus():
Because the window is visible but not focused, shouldReadOnReportChange is false, so readNewestAction is never called and the read is only flagged as skipped. The skipped read is completed only when the unread action later scrolls into view (completeSkippedMarkAsRead → onUnreadActionVisible), but the action is already at the bottom in view, so onViewableItemsChanged never re-fires it and the read is never completed. As a result Onyx lastReadTime is never advanced, so ReportUtils.isUnread keeps returning true (LHN stays unread), and on reopen useUnreadMarker re-seeds unreadMarkerTime from the stale lastReadTime and re-anchors the marker on the still-unread action — so the "New" marker reappears above a message I already saw.
The marker-display gate has the same focus assumption, so it also shows the marker live while the window is unfocused:
What changes do you think we should make in order to solve the problem?
The signal for "the user has viewed this new message" should be "the report is visible AND scrolled to the latest message", not "the window has OS focus." The report being visible with the newest action rendered at the bottom already means the message is on screen — OS focus adds nothing except this false negative.
Core fix — drop the hasFocus() requirement from the mark-as-read gate in useMarkAsRead.ts (the isVisible && isScrolledToEnd guards already guarantee the message is on screen):
This advances lastReadTime as soon as the message is seen, which fixes both symptoms: the LHN no longer shows unread, and on reopen there is no stale unread action left to anchor the "New" marker.
Supporting change — align the live marker gate so it stays consistent with the persisted read state. In useUnreadMarker.ts the scan currently passes hasWindowFocus: Visibility.hasFocus(); switch that to Visibility.isVisible() so shouldDisplayNewMarkerOnReportAction (line 99 above) only shows the marker for genuinely-out-of-view messages (tab hidden via !isVisible, or scrolled away via isScrolledOverThreshold) rather than merely-unfocused ones. This resolves the split-brain the local unreadMarkerTime push-down in useUnreadMarker.ts was papering over:
What alternative solutions did you explore? (Optional)
Complete the skipped read more aggressively (e.g. fire completeSkippedMarkAsRead from a visibility/newest-action effect instead of only on scroll-into-view). I rejected this because completeSkippedMarkAsRead itself is gated on Visibility.hasFocus(), so it would still never run in the visible-but-unfocused case — it treats the symptom, not the root focus assumption.
Emit readNewestAction_ (pass shouldResetUnreadMarker=true) on the report-change read path to keep useUnreadMarker.unreadMarkerTime in sync. This helps the marker resync but does nothing when readNewestAction is never called in the first place, which is the actual failure here.
Please re-state the problem that we are trying to solve in this issue.
On Web, when a new message arrives while the user is actively viewing a conversation scrolled to the most recent message, the chat is incorrectly flipped to "unread" in the LHN and — after leaving and reopening the conversation — a new-message marker is rendered above the just-viewed message. Expected: an incoming message that is already on-screen for a focused, scrolled-to-end viewer should be marked read immediately, so the LHN stays read and no marker appears on reopen.
What is the root cause of that problem?
In src/hooks/useMarkAsRead.ts, the "mark as read on new incoming action" path (handleReportChangeMarkAsRead, lines 101–124, triggered by the effect at lines 127–129) is keyed on report?.lastVisibleActionCreated but reads lastAction = sortedVisibleReportActions.at(0) (line 69) and evaluates isUnread(report, ...) / isCurrentActionUnread(report, lastAction, sortedVisibleReportActions) (lines 107–108). When the server pushes the new action, report.lastVisibleActionCreated and the action's own arrival into sortedVisibleReportActions are not guaranteed to land in the same render pass. When lastVisibleActionCreated updates first, lastAction is still the previous (already-read) action, both guards read as "already read", and the effect early-returns at line 108 without calling readNewestAction. Because sortedVisibleReportActions is not in the dependency list at line 129, the effect never re-fires when the new action does land, so the server-side lastReadTime is never advanced past the new message. The LHN row stays unread (server sees it unread), and on remount useUnreadMarker ([src/hooks/useUnreadMarker.ts:62](https://github.com/Expensify/App/blob/73c7450a7cacb10d251a2c43a4a8447f585b5330/src/hooks/useUnreadMarker.ts#L62)–67) reinitializes unreadMarkerTime from that stale report.lastReadTime, so getUnreadMarkerReportAction places the marker above the just-viewed message.
What changes do you think we should make in order to solve the problem?
[src/hooks/useMarkAsRead.ts:127](https://github.com/Expensify/App/blob/73c7450a7cacb10d251a2c43a4a8447f585b5330/src/hooks/useMarkAsRead.ts#L127)–129 — add sortedVisibleReportActions (or specifically lastAction?.created / lastAction?.reportActionID) to the dependency array of the useEffect that calls handleReportChangeMarkAsRead, so a late-arriving action still triggers the mark-as-read pass on a focused, scrolled-to-end viewer.
[src/hooks/useMarkAsRead.ts:107](https://github.com/Expensify/App/blob/73c7450a7cacb10d251a2c43a4a8447f585b5330/src/hooks/useMarkAsRead.ts#L107)–110 — evaluate "is this incoming action unread" against the latest action from sortedVisibleReportActions AND against report.lastVisibleActionCreated > report.lastReadTime, so an out-of-sync render where only lastVisibleActionCreated has advanced still detects the unread condition instead of early-returning.
src/hooks/useMarkAsRead.ts:112 — keep the isVisible && Visibility.hasFocus() && !hasNewerActions && isScrolledToEnd gate; only broaden the trigger, not the criteria that decide it's safe to mark read.
Add a Jest test for useMarkAsRead covering: report is focused + scrolled to end, a new action arrives such that report.lastVisibleActionCreated updates one render before sortedVisibleReportActions — assert readNewestAction is called exactly once with the newest action's timestamp.
Verify [src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx:371](https://github.com/Expensify/App/blob/73c7450a7cacb10d251a2c43a4a8447f585b5330/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx#L371),405,451 (the MoneyRequestReport twin of the same logic) does not carry the same race; if it does, apply the same dependency fix there.
What alternative solutions did you explore? (Optional)
Push readNewestAction from useReportActionsNewActionLiveTail when it observes a new action while focused + scrolled-to-end, bypassing useMarkAsRead's effect ordering entirely — cleaner but larger blast radius.
When a new message arrives while the report is already open at the newest visible message, useMarkAsRead only calls readNewestAction() if the report is focused, scrolled to the end, and hasNewerActions is false (source). However the pagination layer can include known newer/Pusher-delivered actions in the rendered data while still reporting hasNewerActions because the current page is not marked with PAGINATION_START_ID. In that state the newest incoming message is visible, but useMarkAsRead skips the read call. Since LHN unread state is derived from lastReadTime < lastVisibleActionCreated (source) and the LHN row uses that derived value (source), the report stays unread even though the user saw the message. On reopen, the unread marker is computed from the stale lastReadTime (source), so the viewed message gets a new-message marker.
What changes do you think we should make in order to solve the problem?
Update the read decision in useMarkAsRead so hasNewerActions does not block marking read when the newest visible action is already the report’s latest visible action. The hook already has lastAction and the report data, so it should derive a local hasNewestVisibleAction by comparing lastAction.created with getReportLastVisibleActionCreated(report, transactionThreadReport) and by allowing report preview actions the same way the scroll hook does. Then shouldReadOnReportChange should require the user to be focused/visible and scrolled to the end, plus either no newer actions are pending or the newest report action is already visible.
That keeps the existing guard for true middle-of-history/paginated-gap cases, but lets the normal live-tail case call readNewestAction() when the user is already looking at the incoming message. readNewestAction() already optimistically merges the new lastReadTime and sends ReadNewestAction (source), so once this path fires the LHN no longer stays unread and reopening the conversation will not anchor the unread marker to the already-viewed message.
What alternative solutions did you explore? (Optional)
I also considered changing the pagination hasNewerActions calculation, but that flag is still useful for real paginated gaps. The smaller fix is to keep pagination semantics unchanged and make the read logic check whether the latest report action is actually visible before deciding to skip ReadNewestAction.
When the second user sends the messages, the main user's browser window is visible but not OS-focused (the tester is typing in the other window). In that case useMarkAsRead deliberately skips readNewestAction and only remembers the skip in readActionSkippedRef:
// Only re-run when app visibility/focus changes, so action updates don't keep marking the report as read.
useEffect(()=>{
handleAppVisibilityMarkAsRead(isFocused);
},[isVisible,isFocused]);
but on web isVisible is driven by the Page Visibility API (AppState/visibilitychange), which does not fire when the user clicks back into an already-visible window — only document.hasFocus() changes, and nothing listens to window focus:
The other path, completeSkippedMarkAsRead, is invoked from list viewability changes at the moment the message arrives, but it bails because the window is still unfocused — and it is never invoked again since the user is already at the bottom and no further viewability change happens:
So the report's lastReadTime is never updated → the chat stays bold/unread in LHN even though the user is looking at the newest message. On reopening, useUnreadMarker seeds the marker time from that stale lastReadTime, so the "New" marker is drawn above messages that were already viewed:
What changes do you think we should make in order to solve the problem?
Make the refocus path actually observe window focus. The app already has a cross-platform hook for exactly this, useAppFocusEvent (window focus on web, AppState on native):
handleAppVisibilityMarkAsRead already contains all the right guards (visible, focused, scrolled to end, has an unread action from another user), so regaining window focus while viewing the newest message marks the report read — LHN clears and no marker appears on reopen.
MoneyRequestReportActionsList duplicates the same effect with the same [isFocused, isVisible] dependencies and needs the same one-line subscription:
// This effect logic to `mark as read` will only run when the report focused has new messages and the App visibility
// is changed to visible(meaning user switched to app/web, while user was previously using different tab or application).
// We will mark the report as read in the above case which marks the LHN report item as read while showing the new message
// marker for the chat messages received while the user wasn't focused on the report or on another browser tab for web.
// This effect should only run when app visibility/focus changes; the helper reads the latest report/action values without making every action update mark the report as read.
What alternative solutions did you explore? (Optional)
Track window focus as state (a useHasWindowFocus hook listening to focus/blur) and add it to the effect dependencies in both places. Works too, but reusing useAppFocusEvent is smaller and avoids extra re-renders on every blur.
🚨 Edited by proposal-police: This proposal was edited at 2026-07-10 20:19:35 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a message arrives while the user has the conversation open and in view, the chat gets marked unread in the LHN and stays that way; reopening the chat later shows the green "new messages" marker even though the user already saw the message on screen.
What is the root cause of that problem?
This is a regression from PR #93387 ("fix: show desktop notification when active chat is open but app is unfocused", merged 2026-06-18). That PR intentionally stopped marking a chat read when a message arrives while the browser window is visible but not OS-focused (so the desktop notification + LHN unread state can appear), and it originally added a window-focus catch-up to mark the chat read once the user refocuses. A later commit in the same PR (5ce49698ad, "fix: remove unnecessary focus catch-up") deleted that catch-up — including its own comment explaining why it was needed: "A visible browser window can regain OS focus without a visibility change, so rerun the read catch-up on app focus too." The structural cause: every remaining mark-as-read trigger is keyed to signals that do not fire on an OS window-focus change, so a read skipped for "unfocused" can never complete.
The verified chain (repro: tester keeps the chat in view in window A and sends from the secondary user's window B, so A is visible but unfocused):
The message arrives; the report-change handler runs but shouldReadOnReportChange fails its Visibility.hasFocus() term, so instead of readNewestAction it only sets readActionSkippedRef.current = true (intentional per #93387) — LHN shows unread:
The viewability tracker fires onUnreadActionVisible (the new message is on screen), but completeSkippedMarkAsRead early-returns on the same !Visibility.hasFocus() check — and it is only re-invoked on a viewability change, which never happens again if the user doesn't scroll:
The user clicks back into window A. On web, Visibility.onVisibilityChange maps to AppState/visibilitychange, which does not fire on window focus (document.visibilityState stays visible):
// Only re-run when app visibility/focus changes, so action updates don't keep marking the report as read.
useEffect(()=>{
handleAppVisibilityMarkAsRead(isFocused);
},[isVisible,isFocused]);
Net result: lastReadTime never advances → the chat stays bold in LHN while the user is reading it (symptom 1). On leaving and reopening, useUnreadMarker computes the green line from the stale lastReadTime, and the marker intentionally persists for the session even after the reopen marks the report read (symptom 2):
// This effect logic to `mark as read` will only run when the report focused has new messages and the App visibility
// is changed to visible(meaning user switched to app/web, while user was previously using different tab or application).
// We will mark the report as read in the above case which marks the LHN report item as read while showing the new message
// marker for the chat messages received while the user wasn't focused on the report or on another browser tab for web.
// This effect should only run when app visibility/focus changes; the helper reads the latest report/action values without making every action update mark the report as read.
Native is unaffected: foregrounding fires AppState change, flipping isVisible, so the existing effect covers it — consistent with only web platforms being reproducible.
What changes do you think we should make in order to solve the problem?
Restore the window-focus catch-up that commit 5ce49698ad removed, using the existing useAppFocusEvent hook (web impl listens to windowfocus:
In useMarkAsRead.ts, re-run the existing catch-up handler on app focus:
// A visible browser window can regain OS focus without a visibility change,// so rerun the read catch-up on app focus too.consthandleAppFocusCatchUp=useEffectEvent(()=>handleAppVisibilityMarkAsRead(isFocused));useAppFocusEvent(handleAppFocusCatchUp);
In MoneyRequestReportActionsList.tsx, extract the body of the [isFocused, isVisible] effect into an effect event (as it was before, markAsReadWhenVisibleAndFocused) and wire it to both the effect and useAppFocusEvent.
Regression safety in one sentence: the focus event only re-runs the existing handler, which itself re-validates visible + focused + scrolled-to-bottom + has-unread-from-others before calling readNewestAction, so tab-switch, native AppState, notification-open, and scrolled-up flows are unchanged.
Why the obvious spot-fix does not work: dropping the Visibility.hasFocus() term from shouldReadOnReportChange (useMarkAsRead.ts#L112) re-breaks PR #93387 — messages arriving while the window is unfocused would be instantly marked read again, suppressing the desktop notification and LHN unread state that gate was added to produce. The equally tempting useAppFocusEvent(completeSkippedMarkAsRead) is also wrong: readActionSkippedRef is set on every skipped read, including when the user is scrolled up in history (L123 also runs when isScrolledToEnd is false), so a bare focus→complete would mark messages read that were never on screen; the full catch-up handler re-checks in-view state first.
What alternative solutions did you explore? (Optional)
Remove the hasFocus() gate at the arrival site — reverts #93387's intended desktop-notification behavior (see above).
Make Visibility.onVisibilityChange also subscribe to window focus/blur — fixes this bug but changes semantics for every other consumer of that shared lib (large blast radius); the scoped useAppFocusEvent restore is safer.
useAppFocusEvent(completeSkippedMarkAsRead) only — incomplete: over-marks when scrolled up, and misses the MoneyRequestReportActionsList copy entirely.
The active report can intentionally skip readNewestAction() when the report's newest action changes while the local action window still reports hasNewerActions. That is the right guard while the newest action is not loaded yet, but the skipped read is only completed when the unread-marker action becomes viewable.
For a message received from another user while the chat is already focused at the bottom, the marker helper deliberately suppresses a marker for that newly inserted, already-visible action. So the report can stay unread in the LHN, and on the next open the stale lastReadTime is used to anchor the new-message marker even though the user already saw the message.
This regression comes from the first-unread/live-tail pagination work in commit 02fa27017178bc278dab524a5eaaca563546a048, which added the hasNewerActions skip condition and live-tail catch-up flow without adding a follow-up read completion when the user is still at the bottom after the newer window finishes loading.
What changes do you think we should make in order to solve the problem?
Update useMarkAsRead so a skipped mark-as-read is completed once all of these are true: a read was previously skipped, the app window/report is focused, the list is still scrolled to the end, and hasNewerActions is false. This keeps the existing initial unread-anchor and live-tail guards, but closes the pending read after the newest action is actually available and visible.
The main chat call site already passes both isScrolledToEnd and hasNewerActions, so the fix can stay inside useMarkAsRead instead of changing the marker scan or the report action list rendering.
Add a useMarkAsRead unit test that starts with hasNewerActions: true and isScrolledToEnd: true, verifies the read is skipped after the newest-action change, then rerenders with hasNewerActions: false and verifies readNewestAction(reportID, true) runs.
Keep/extend the unread-indicator UI coverage that verifies no new line indicator is shown for another user's newly received message while the report is open.
What alternative solutions did you explore? (Optional)
I considered changing shouldDisplayNewMarkerOnReportAction() to return a marker for new messages from another user even when the chat is focused at the bottom. That would make the existing viewability callback complete the skipped read, but it conflicts with the existing product behavior and test coverage that visible live incoming messages should not draw a new-message line.
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Activity
applause-bot commentedon Jul 10, 2026
While Applause doesn't embed attachments for this bug, here are the links for quick view:
https://platform.applause.com/services/links/v1/external/b1d3a7bddc94540ca43f624dc388a5b93527d2022809bbf912023f9c5909cfb4
MelvinBot commentedon Jul 10, 2026
Proposal
What is the root cause of that problem?
The "new message" marker and the LHN unread state are both driven by
report.lastReadTime. On (re)open,useUnreadMarkerseeds the marker time fromreport.lastReadTime, and a message shows the marker wheneverlastReadTime < message.created(isReportActionUnread).lastReadTimeis only advanced byreadNewestAction. When a message arrives while you're viewing the chat, the auto-mark-as-read inuseMarkAsReadis gated:If that gate is false,
readNewestActionis skipped,readActionSkippedRefis set, andlastReadTimeis never advanced. The only recovery (completeSkippedMarkAsRead) requires the unread marker to scroll back into view while focused — so if the user leaves first,lastReadTimestays stale. On reopen the marker is re-seeded from that stale value and reappears over an already-viewed message. The LHN staying unread is consistent withlastReadTimenever advancing.The gate's
isScrolledToEndterm (= !hasScrolledOverThreshold, a 250px threshold —ReportActionsList.tsx:195) is the most likely culprit.hasScrolledOverThresholdis state that is only updated byonScroll(ReportActionsList.tsx:294-297). If the user scrolled up (loading history / glancing back) and returned to the bottom via a programmaticscrollToBottom(a non-animatedscrollToIndex) that doesn't emit a settlingonScroll,hasScrolledOverThresholdstays stale-trueeven though the user is visually at the newest message — so the next inbound message hits the failing branch.Investigation details & code trace
Marker computation (reopen):
report.lastReadTime:useUnreadMarker.ts:62-67lastReadTime < created:isReportActionUnreadviashouldDisplayNewMarkerOnReportAction.ts:65Mark-as-read gate (new message while viewing):
useMarkAsRead.ts:101-124(fires onreport.lastVisibleActionCreatedchange)readNewestActionwriteslastReadTime:Report/index.ts:2788-2825ACTION_VISIBLE_THRESHOLD = 250:CONST/index.ts:1776Why "at the bottom" can still fail: the list is inverted (bottom ≈ offset 0), so appending a message does not spike the offset.
hasScrolledOverThresholdand the pin-to-bottomscrollOffsetRef(useScrollToEndOnNewMessageReceived.ts:65-82) are both only updated byonScroll, so a programmatic return-to-bottom that doesn't emitonScrollleaves them stale-high.Alternatives considered: stale closure in the effect (ruled out — the gate runs inside a
useEffectEvent, always current);hasNewerActionstrue while at the live tail (ruled out for this repro — it'shasPreviousPage, false when viewing the newest message);isVisible/Visibility.hasFocus()momentarily false (possible secondary trigger).Confidence: High on the mechanism (stale
lastReadTime→ marker on reopen). Medium on the exact sub-trigger — runtime logging ofisScrolledToEnd/scrollOffsetRef/contentOffset.yat the momenthandleReportChangeMarkAsReadruns would pin it down. No accountID/reportID in the report to scope a production log query.What changes do you think we should make in order to solve the problem?
Make read-state robust to a stale scroll gate so
lastReadTimeadvances whenever a message is genuinely viewed:hasScrolledOverThreshold(and thescrollOffsetRefused by the pin-to-bottom logic) to their below-threshold values, instead of waiting for anonScrollthat may never fire — soisScrolledToEndreflects reality.readActionSkippedRefwhen the report is visible + focused and the newest action is rendered, rather than only when the unread marker scrolls into view — so leaving the chat doesn't strand a skipped mark-as-read.What alternative solutions did you explore? (Optional)
Emitting
onScroll(or its state update) after every programmaticscrollToBottom; and re-running the mark-as-read gate on report blur/unmount when the newest action is on screen.Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/95871)to create a draft PR.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal.
yusufdeveloper2903 commentedon Jul 10, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a new message arrives while I have the conversation open, scrolled to the latest message, and visible on screen — but the browser window does not hold OS focus (e.g. focus is on another window/tab) — the report is marked unread in the LHN, and after leaving and reopening the conversation a "New" message marker is shown above a message I already saw.
What is the root cause of that problem?
The read logic uses
Visibility.hasFocus()(OS window focus) as the proxy for "the user has viewed this message." But a conversation can be fully visible on screen and scrolled to the newest message without the window holding OS focus — which is exactly what happens in the repro, where the same tester keeps the main user's conversation in view while sending from the secondary user's window (that second window takes OS focus).When a new action lands,
handleReportChangeMarkAsReaddecides whether to mark the report read, and it requiresVisibility.hasFocus():https://github.com/Expensify/App/blob/main/src/hooks/useMarkAsRead.ts#L111-L124
Because the window is visible but not focused,
shouldReadOnReportChangeisfalse, soreadNewestActionis never called and the read is only flagged as skipped. The skipped read is completed only when the unread action later scrolls into view (completeSkippedMarkAsRead→onUnreadActionVisible), but the action is already at the bottom in view, soonViewableItemsChangednever re-fires it and the read is never completed. As a result OnyxlastReadTimeis never advanced, soReportUtils.isUnreadkeeps returningtrue(LHN stays unread), and on reopenuseUnreadMarkerre-seedsunreadMarkerTimefrom the stalelastReadTimeand re-anchors the marker on the still-unread action — so the "New" marker reappears above a message I already saw.The marker-display gate has the same focus assumption, so it also shows the marker live while the window is unfocused:
https://github.com/Expensify/App/blob/main/src/pages/inbox/report/shouldDisplayNewMarkerOnReportAction.ts#L96-L99
What changes do you think we should make in order to solve the problem?
The signal for "the user has viewed this new message" should be "the report is visible AND scrolled to the latest message", not "the window has OS focus." The report being visible with the newest action rendered at the bottom already means the message is on screen — OS focus adds nothing except this false negative.
Core fix — drop the
hasFocus()requirement from the mark-as-read gate inuseMarkAsRead.ts(theisVisible && isScrolledToEndguards already guarantee the message is on screen):This advances
lastReadTimeas soon as the message is seen, which fixes both symptoms: the LHN no longer shows unread, and on reopen there is no stale unread action left to anchor the "New" marker.Supporting change — align the live marker gate so it stays consistent with the persisted read state. In
useUnreadMarker.tsthe scan currently passeshasWindowFocus: Visibility.hasFocus(); switch that toVisibility.isVisible()soshouldDisplayNewMarkerOnReportAction(line 99 above) only shows the marker for genuinely-out-of-view messages (tab hidden via!isVisible, or scrolled away viaisScrolledOverThreshold) rather than merely-unfocused ones. This resolves the split-brain the localunreadMarkerTimepush-down inuseUnreadMarker.tswas papering over:https://github.com/Expensify/App/blob/main/src/hooks/useUnreadMarker.ts#L135-L141
What alternative solutions did you explore? (Optional)
completeSkippedMarkAsReadfrom a visibility/newest-action effect instead of only on scroll-into-view). I rejected this becausecompleteSkippedMarkAsReaditself is gated onVisibility.hasFocus(), so it would still never run in the visible-but-unfocused case — it treats the symptom, not the root focus assumption.readNewestAction_(passshouldResetUnreadMarker=true) on the report-change read path to keepuseUnreadMarker.unreadMarkerTimein sync. This helps the marker resync but does nothing whenreadNewestActionis never called in the first place, which is the actual failure here.aswin-s commentedon Jul 10, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
On Web, when a new message arrives while the user is actively viewing a conversation scrolled to the most recent message, the chat is incorrectly flipped to "unread" in the LHN and — after leaving and reopening the conversation — a new-message marker is rendered above the just-viewed message. Expected: an incoming message that is already on-screen for a focused, scrolled-to-end viewer should be marked read immediately, so the LHN stays read and no marker appears on reopen.
What is the root cause of that problem?
In
src/hooks/useMarkAsRead.ts, the "mark as read on new incoming action" path (handleReportChangeMarkAsRead, lines 101–124, triggered by the effect at lines 127–129) is keyed onreport?.lastVisibleActionCreatedbut readslastAction = sortedVisibleReportActions.at(0)(line 69) and evaluatesisUnread(report, ...)/isCurrentActionUnread(report, lastAction, sortedVisibleReportActions)(lines 107–108). When the server pushes the new action,report.lastVisibleActionCreatedand the action's own arrival intosortedVisibleReportActionsare not guaranteed to land in the same render pass. WhenlastVisibleActionCreatedupdates first,lastActionis still the previous (already-read) action, both guards read as "already read", and the effect early-returns at line 108 without callingreadNewestAction. BecausesortedVisibleReportActionsis not in the dependency list at line 129, the effect never re-fires when the new action does land, so the server-sidelastReadTimeis never advanced past the new message. The LHN row stays unread (server sees it unread), and on remountuseUnreadMarker([src/hooks/useUnreadMarker.ts:62](https://github.com/Expensify/App/blob/73c7450a7cacb10d251a2c43a4a8447f585b5330/src/hooks/useUnreadMarker.ts#L62)–67) reinitializesunreadMarkerTimefrom that stalereport.lastReadTime, sogetUnreadMarkerReportActionplaces the marker above the just-viewed message.What changes do you think we should make in order to solve the problem?
[src/hooks/useMarkAsRead.ts:127](https://github.com/Expensify/App/blob/73c7450a7cacb10d251a2c43a4a8447f585b5330/src/hooks/useMarkAsRead.ts#L127)–129— addsortedVisibleReportActions(or specificallylastAction?.created/lastAction?.reportActionID) to the dependency array of theuseEffectthat callshandleReportChangeMarkAsRead, so a late-arriving action still triggers the mark-as-read pass on a focused, scrolled-to-end viewer.[src/hooks/useMarkAsRead.ts:107](https://github.com/Expensify/App/blob/73c7450a7cacb10d251a2c43a4a8447f585b5330/src/hooks/useMarkAsRead.ts#L107)–110— evaluate "is this incoming action unread" against the latest action fromsortedVisibleReportActionsAND againstreport.lastVisibleActionCreated > report.lastReadTime, so an out-of-sync render where onlylastVisibleActionCreatedhas advanced still detects the unread condition instead of early-returning.isVisible && Visibility.hasFocus() && !hasNewerActions && isScrolledToEndgate; only broaden the trigger, not the criteria that decide it's safe to mark read.useMarkAsReadcovering: report is focused + scrolled to end, a new action arrives such thatreport.lastVisibleActionCreatedupdates one render beforesortedVisibleReportActions— assertreadNewestActionis called exactly once with the newest action's timestamp.[src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx:371](https://github.com/Expensify/App/blob/73c7450a7cacb10d251a2c43a4a8447f585b5330/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx#L371),405,451(the MoneyRequestReport twin of the same logic) does not carry the same race; if it does, apply the same dependency fix there.What alternative solutions did you explore? (Optional)
Push
readNewestActionfromuseReportActionsNewActionLiveTailwhen it observes a new action while focused + scrolled-to-end, bypassinguseMarkAsRead's effect ordering entirely — cleaner but larger blast radius.nabi-ebrahimi commentedon Jul 10, 2026
Proposal
What is the root cause of that problem?
When a new message arrives while the report is already open at the newest visible message,
useMarkAsReadonly callsreadNewestAction()if the report is focused, scrolled to the end, andhasNewerActionsis false (source). However the pagination layer can include known newer/Pusher-delivered actions in the rendered data while still reportinghasNewerActionsbecause the current page is not marked withPAGINATION_START_ID. In that state the newest incoming message is visible, butuseMarkAsReadskips the read call. Since LHN unread state is derived fromlastReadTime < lastVisibleActionCreated(source) and the LHN row uses that derived value (source), the report stays unread even though the user saw the message. On reopen, the unread marker is computed from the stalelastReadTime(source), so the viewed message gets a new-message marker.What changes do you think we should make in order to solve the problem?
Update the read decision in
useMarkAsReadsohasNewerActionsdoes not block marking read when the newest visible action is already the report’s latest visible action. The hook already haslastActionand the report data, so it should derive a localhasNewestVisibleActionby comparinglastAction.createdwithgetReportLastVisibleActionCreated(report, transactionThreadReport)and by allowing report preview actions the same way the scroll hook does. ThenshouldReadOnReportChangeshould require the user to be focused/visible and scrolled to the end, plus either no newer actions are pending or the newest report action is already visible.That keeps the existing guard for true middle-of-history/paginated-gap cases, but lets the normal live-tail case call
readNewestAction()when the user is already looking at the incoming message.readNewestAction()already optimistically merges the newlastReadTimeand sendsReadNewestAction(source), so once this path fires the LHN no longer stays unread and reopening the conversation will not anchor the unread marker to the already-viewed message.What alternative solutions did you explore? (Optional)
I also considered changing the pagination
hasNewerActionscalculation, but that flag is still useful for real paginated gaps. The smaller fix is to keep pagination semantics unchanged and make the read logic check whether the latest report action is actually visible before deciding to skipReadNewestAction.lorretheboy commentedon Jul 10, 2026
Proposal
What is the root cause of that problem?
When the second user sends the messages, the main user's browser window is visible but not OS-focused (the tester is typing in the other window). In that case
useMarkAsReaddeliberately skipsreadNewestActionand only remembers the skip inreadActionSkippedRef:App/src/hooks/useMarkAsRead.ts
Lines 112 to 123 in 73c7450
The skip is supposed to be completed when the user comes back, but neither completion path can ever fire on web:
isVisibleor the navigationisFocusedchanges:App/src/hooks/useMarkAsRead.ts
Lines 169 to 172 in 73c7450
but on web
isVisibleis driven by the Page Visibility API (AppState/visibilitychange), which does not fire when the user clicks back into an already-visible window — onlydocument.hasFocus()changes, and nothing listens to windowfocus:App/src/libs/Visibility/index.ts
Lines 18 to 23 in 73c7450
completeSkippedMarkAsRead, is invoked from list viewability changes at the moment the message arrives, but it bails because the window is still unfocused — and it is never invoked again since the user is already at the bottom and no further viewability change happens:App/src/hooks/useMarkAsRead.ts
Lines 179 to 184 in 73c7450
So the report's
lastReadTimeis never updated → the chat stays bold/unread in LHN even though the user is looking at the newest message. On reopening,useUnreadMarkerseeds the marker time from that stalelastReadTime, so the "New" marker is drawn above messages that were already viewed:App/src/hooks/useUnreadMarker.ts
Line 67 in 73c7450
What changes do you think we should make in order to solve the problem?
Make the refocus path actually observe window focus. The app already has a cross-platform hook for exactly this,
useAppFocusEvent(windowfocuson web, AppState on native):App/src/hooks/useAppFocusEvent/index.ts
Lines 10 to 18 in 73c7450
In
useMarkAsRead, subscribe with it and run the existing handler when focus returns, e.g.:handleAppVisibilityMarkAsReadalready contains all the right guards (visible, focused, scrolled to end, has an unread action from another user), so regaining window focus while viewing the newest message marks the report read — LHN clears and no marker appears on reopen.MoneyRequestReportActionsListduplicates the same effect with the same[isFocused, isVisible]dependencies and needs the same one-line subscription:App/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx
Lines 383 to 414 in 73c7450
What alternative solutions did you explore? (Optional)
Track window focus as state (a
useHasWindowFocushook listening tofocus/blur) and add it to the effect dependencies in both places. Works too, but reusinguseAppFocusEventis smaller and avoids extra re-renders on every blur.ahmdshrif commentedon Jul 10, 2026
🚨 Edited by proposal-police: This proposal was edited at 2026-07-10 20:19:35 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a message arrives while the user has the conversation open and in view, the chat gets marked unread in the LHN and stays that way; reopening the chat later shows the green "new messages" marker even though the user already saw the message on screen.
What is the root cause of that problem?
This is a regression from PR
#93387("fix: show desktop notification when active chat is open but app is unfocused", merged 2026-06-18). That PR intentionally stopped marking a chat read when a message arrives while the browser window is visible but not OS-focused (so the desktop notification + LHN unread state can appear), and it originally added a window-focus catch-up to mark the chat read once the user refocuses. A later commit in the same PR (5ce49698ad, "fix: remove unnecessary focus catch-up") deleted that catch-up — including its own comment explaining why it was needed: "A visible browser window can regain OS focus without a visibility change, so rerun the read catch-up on app focus too." The structural cause: every remaining mark-as-read trigger is keyed to signals that do not fire on an OS window-focus change, so a read skipped for "unfocused" can never complete.The verified chain (repro: tester keeps the chat in view in window A and sends from the secondary user's window B, so A is visible but unfocused):
shouldReadOnReportChangefails itsVisibility.hasFocus()term, so instead ofreadNewestActionit only setsreadActionSkippedRef.current = true(intentional per#93387) — LHN shows unread:App/src/hooks/useMarkAsRead.ts
Lines 101 to 124 in 73c7450
onUnreadActionVisible(the new message is on screen), butcompleteSkippedMarkAsReadearly-returns on the same!Visibility.hasFocus()check — and it is only re-invoked on a viewability change, which never happens again if the user doesn't scroll:App/src/hooks/useMarkAsRead.ts
Lines 179 to 184 in 73c7450
App/src/pages/inbox/report/useReportUnreadMessageScrollTracking.ts
Lines 157 to 161 in 73c7450
Visibility.onVisibilityChangemaps to AppState/visibilitychange, which does not fire on window focus (document.visibilityStatestaysvisible):App/src/libs/Visibility/index.ts
Lines 8 to 23 in 73c7450
[isVisible, isFocused], and neither changes — so it never runs:App/src/hooks/useMarkAsRead.ts
Lines 169 to 172 in 73c7450
lastReadTimenever advances → the chat stays bold in LHN while the user is reading it (symptom 1). On leaving and reopening,useUnreadMarkercomputes the green line from the stalelastReadTime, and the marker intentionally persists for the session even after the reopen marks the report read (symptom 2):App/src/pages/inbox/report/ReportActionsList.tsx
Lines 181 to 197 in 73c7450
Affected paths — the same skip-without-recovery pattern exists in both report lists (the deleted commit removed the catch-up from both):
useMarkAsRead.ts(above), used byReportActionsList.tsx.MoneyRequestReportActionsList.tsxhas its own copy of the gate and skip (App/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx
Lines 368 to 377 in 73c7450
[isFocused, isVisible]-keyed catch-up (App/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx
Lines 383 to 415 in 73c7450
change, flippingisVisible, so the existing effect covers it — consistent with only web platforms being reproducible.What changes do you think we should make in order to solve the problem?
Restore the window-focus catch-up that commit
5ce49698adremoved, using the existinguseAppFocusEventhook (web impl listens towindowfocus:App/src/hooks/useAppFocusEvent/index.ts
Lines 10 to 18 in 73c7450
In
useMarkAsRead.ts, re-run the existing catch-up handler on app focus:In
MoneyRequestReportActionsList.tsx, extract the body of the[isFocused, isVisible]effect into an effect event (as it was before,markAsReadWhenVisibleAndFocused) and wire it to both the effect anduseAppFocusEvent.Regression safety in one sentence: the focus event only re-runs the existing handler, which itself re-validates visible + focused + scrolled-to-bottom + has-unread-from-others before calling
readNewestAction, so tab-switch, native AppState, notification-open, and scrolled-up flows are unchanged.Why the obvious spot-fix does not work: dropping the
Visibility.hasFocus()term fromshouldReadOnReportChange(useMarkAsRead.ts#L112) re-breaks PR#93387— messages arriving while the window is unfocused would be instantly marked read again, suppressing the desktop notification and LHN unread state that gate was added to produce. The equally temptinguseAppFocusEvent(completeSkippedMarkAsRead)is also wrong:readActionSkippedRefis set on every skipped read, including when the user is scrolled up in history (L123 also runs whenisScrolledToEndis false), so a bare focus→complete would mark messages read that were never on screen; the full catch-up handler re-checks in-view state first.What alternative solutions did you explore? (Optional)
hasFocus()gate at the arrival site — reverts#93387's intended desktop-notification behavior (see above).Visibility.onVisibilityChangealso subscribe to windowfocus/blur— fixes this bug but changes semantics for every other consumer of that shared lib (large blast radius); the scopeduseAppFocusEventrestore is safer.useAppFocusEvent(completeSkippedMarkAsRead)only — incomplete: over-marks when scrolled up, and misses theMoneyRequestReportActionsListcopy entirely.KJ21-ENG commentedon Jul 10, 2026
Proposal
What is the root cause of that problem?
The active report can intentionally skip
readNewestAction()when the report's newest action changes while the local action window still reportshasNewerActions. That is the right guard while the newest action is not loaded yet, but the skipped read is only completed when the unread-marker action becomes viewable.App/src/hooks/useMarkAsRead.ts
Lines 101 to 129 in 73c7450
For a message received from another user while the chat is already focused at the bottom, the marker helper deliberately suppresses a marker for that newly inserted, already-visible action. So the report can stay unread in the LHN, and on the next open the stale
lastReadTimeis used to anchor the new-message marker even though the user already saw the message.App/src/pages/inbox/report/shouldDisplayNewMarkerOnReportAction.ts
Lines 76 to 99 in 73c7450
This regression comes from the first-unread/live-tail pagination work in commit
02fa27017178bc278dab524a5eaaca563546a048, which added thehasNewerActionsskip condition and live-tail catch-up flow without adding a follow-up read completion when the user is still at the bottom after the newer window finishes loading.App/src/hooks/usePaginatedReportActions.ts
Lines 90 to 101 in 73c7450
App/src/pages/inbox/report/useReportActionsNewActionLiveTail.ts
Lines 99 to 142 in 73c7450
What changes do you think we should make in order to solve the problem?
Update
useMarkAsReadso a skipped mark-as-read is completed once all of these are true: a read was previously skipped, the app window/report is focused, the list is still scrolled to the end, andhasNewerActionsis false. This keeps the existing initial unread-anchor and live-tail guards, but closes the pending read after the newest action is actually available and visible.App/src/hooks/useMarkAsRead.ts
Lines 174 to 184 in 73c7450
The main chat call site already passes both
isScrolledToEndandhasNewerActions, so the fix can stay insideuseMarkAsReadinstead of changing the marker scan or the report action list rendering.App/src/pages/inbox/report/ReportActionsList.tsx
Lines 190 to 197 in 73c7450
Test coverage:
useMarkAsReadunit test that starts withhasNewerActions: trueandisScrolledToEnd: true, verifies the read is skipped after the newest-action change, then rerenders withhasNewerActions: falseand verifiesreadNewestAction(reportID, true)runs.What alternative solutions did you explore? (Optional)
I considered changing
shouldDisplayNewMarkerOnReportAction()to return a marker for new messages from another user even when the chat is focused at the bottom. That would make the existing viewability callback complete the skipped read, but it conflicts with the existing product behavior and test coverage that visible live incoming messages should not draw a new-message line.App/tests/ui/UnreadIndicatorsTest.tsx
Lines 717 to 735 in 73c7450
melvin-bot commentedon Jul 10, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @abzokhattab (
External)47 remaining items
melvin-bot commentedon Aug 4, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)melvin-bot commentedon Aug 4, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
mallenexpensify commentedon Aug 7, 2026
Payment Summary
Contributor: @lorretheboy paid $250 via Upwork
Contributor+: @abzokhattab due $250 via NewDot
@lorretheboy can you please accept the job below? Please reply here and tag me once you have.
https://www.upwork.com/jobs/~022075676039414134043
^ Test case created. Thx
lorretheboy commentedon Aug 9, 2026
@mallenexpensify I accepted the job. Thx
mallenexpensify commentedon Aug 10, 2026
@lorretheboy paid, summary updated above. Thx.
quinthar commentedon Sep 1, 2026
Approved $250 to @abzokhattab