Skip to content

fix(mobile): phone chat page keeps following after a nudge, per chat, and at 2,000 messages - #28807

Closed
brennanb2025 wants to merge 8 commits into
mainfrom
brennanb2025/mobile-chat-scroll-follow-fixes
Closed

brennanb2025 wants to merge 8 commits into
mainfrom
brennanb2025/mobile-chat-scroll-follow-fixes

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​274 $\color{#cf222e}{\Huge{\mathbf{−}}}$​32 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​242
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​395 $\color{#cf222e}{\Huge{\mathbf{−}}}$​117 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​278

ELI5

#28413 stopped the phone chat from pulling you back to the bottom while you read older messages. A review of that merged change found four ways it misbehaves in the chat the phone app draws as a web page (current phone builds draw it that way; the page ships inside the desktop app):

  1. Nudge up, and the chat silently stops scrolling. During a live reply, moving the list up a little (to re-read a line, or the small bounce after a downward flick) stopped auto-scroll, but the "Scroll to latest" arrow never appeared. New output piled up out of sight below. In a headless browser test: after a 40 px nudge and five new rows, the newest row was 790 px below the screen, with no arrow.
  2. Switching chat tabs kept the last chat's scroll state. Scroll up in chat A, switch to chat B, and B opened somewhere in the middle (at A's scroll offset, or at B's oldest loaded message) instead of at its newest message.
  3. Very long chats stopped following on every message. Once a chat holds 2,000 messages, each new message drops the oldest one. The page corrected the scroll position for the dropped row, then took that correction for the reader scrolling up. So auto-scroll turned off on every new message.
  4. Loading older messages could jump past your place. The code that keeps your place when older messages load anchored the lowest thing on screen. That could be the live status line, which moves when output lands, so you ended up past the message you were reading.

After this PR: a small nudge snaps back to the end and keeps following, as it already does in the native app. Every chat opens at its newest message. Long chats keep following. Loading older messages keeps the message you were reading where it was.

What Changed

All in mobile/src/session/, and only the web-page path (react-native-web) changes behavior. The native app is unchanged except for the per-chat reset (2).

  1. "Let go near the end" snaps back, on the page too (use-mobile-native-chat-tail-follow.ts). The native app knows when the finger lifts: within 80 pt of the end it snaps back and keeps following. The page gets no touch-release events, only scroll positions. It now treats a scroll that has been still for 150 ms as let go (react-native-web sends its last scroll event 100 ms after the view stops). If the view is then within the same 80 pt of the end, it jumps back and follows. So "not following, with no arrow" can't outlast a scroll. Any move up still stops following at once, so a reader dragging up while a reply streams gets away from the bottom. The same rule fixes a related case: the view clamped onto the end after the transcript shrank (for example a reconnect that resets to the last 40 messages) now resumes following instead of sitting at the end, not following, with no arrow.
  2. Per-chat scroll state resets on a chat switch (tail-follow hook and use-mobile-native-chat-page-history.tsx). The chat view stays mounted across chat tabs, so "not following", the page's last scroll offset and the start of the page's loaded-history block carried from one chat to the next. The tail-follow hook now takes the chat's identity and, when it changes, jumps to the newest message before paint. The history block's starting row is stored with the chat it belongs to. Row ids like the streaming bubble's repeat across chats, so an id alone isn't enough.
  3. Only one owner of the scroll position while following (MobileNativeChatScrollHold.tsx). The hold now acts only while the reader is not following. While following, auto-scroll alone places the view, as the hook's own documentation already says. The browser has its own version of the hold, scroll anchoring (overflow-anchor, on in Android's WebView), and it made the same upward correction when the oldest row was dropped. So the hold also turns browser anchoring off while following and back on when not, where it still helps keep rows steady as they render above the reader.
  4. Hold the first message row on screen (MobileNativeChatScrollHold.tsx). The hold now picks the first message row on screen from the top, skipping the "Load earlier messages" control and the footer (live status line and queued messages). Output landing below that row never moves it.

Why

  • Item 1: why not "only count a move up of more than 80 pt as leaving the end"? That was the first idea, and it brings back the bug fix(mobile): keep the chat where the reader scrolled to #28413 fixed. While a reply streams, every bit of new output re-pins the view to the bottom, so a reader dragging up at a normal speed (125–625 px/s in the test) never gets 80 pt away before the next pin pulls them back. Measured in headless Chromium and WebKit: with that rule the reader stayed at the bottom in all three drag speeds. With this PR they get away, and the arrow shows. The settle rule matches what the native app does at the moment of release, using the only release signal the page has.
  • Item 2: why not remount the view per chat with a React key? A remount would also reset things that belong to the view, not to a chat: the Tools expand toggle and pinch-zoom text size both carry across chat tabs today. Composer drafts are owned per tab by the route, so neither option affects them. The view already scopes its other per-chat state (expanded turns) by the same chat identity instead of remounting, and this follows that.
  • Item 3: why turn off browser anchoring rather than only gating our hold? Gating our hold alone left the bug in place in both engines: browser anchoring made the same correction (450 px below with anchoring on, 0 with it off, same test). Turning anchoring off only while following keeps its help for a reader who is scrolled up.

Follows up #28413.

Linked Issue

Follow-up to #28413 (merged). No separate issue.

Visual Proof

Not recorded for this draft. The behavior was measured on react-native-web 0.21.3's real list (the version the phone page uses), driven headlessly in Chromium and WebKit at a 400×700 viewport. The results, each before → after, the same in both engines:

Case Before After
Nudge up 40 px, then 5 new rows 790 px below, no arrow at the end, following
2,000-message ceiling, 3 messages each dropping the oldest 450 px below, arrow, not following at the end, following
Older messages load with the live line and queued messages on screen, plus 300 px of new output the row you were reading moves from 40 px to −260 px stays at 40 px
Scroll up in chat A, open chat B B at 500 px above its end, arrow showing B at its end, following
Transcript shrinks while scrolled up, then 3 new rows (WebKit) 450 px below, no arrow at the end, following
Drag up at 125 / 313 / 625 px/s while a reply streams gets away (arrow) gets away (arrow)

The paging-with-big-history checks from #28413's review (rows stay on screen, every row renders on the way back down) are unchanged.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • New tests, each failing on the merged code: a nudge on the page snaps back and follows; switching chats opens the new chat following; the hold does nothing (and turns browser anchoring off) while following; the hold keeps the reader's row, not the footer.

  • pnpm exec vitest run src/session in mobile/: all pass. Mobile typecheck and the tests-typecheck ratchet pass.

  • Not run on a phone or emulator yet. iOS momentum scrolling in particular hasn't been exercised.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Mobile only. No desktop, wire or SSH change: the page is still served by the desktop as before. Native app builds change only for item 2 (a new chat opens at its newest message).

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…t page

Follow-up to #28413, on the page the OTA phone app draws:

- A small move up during a live turn stopped following with no "Scroll to
  latest" arrow. A scroll that comes to rest within 80 pt of the end now
  returns to it and follows, as letting go there does in the native app.
- Switching chat tabs carried "not following", the page's scroll state and
  the page-history head into the next chat. They are now per chat.
- At the 2,000-message ceiling every new message trims the oldest row; the
  place-hold (ours and the browser's own scroll anchoring) moved the view up
  for it and the page took that for the reader. Holding now happens only
  while not following.
- The hold anchored the lowest element on screen, which could be the live
  status line. It now anchors the first message row on screen.
…llowing

On the page (RN Web), following turned off on any scroll event that read as a move up, so layout
(clamps, re-measures, trims) could detach it, and extra bookkeeping (a settle timer, per-touch ids,
cancel uncertainty) tried to tell reader moves from layout moves. A touch whose element was removed
mid-touch never delivered its end, which stranded the page out of following with no jump control.

Following now turns off only under a reader gesture (a finger on the list per the browser's live
touches list, or a wheel or scroll key, until scrolling goes quiet), and turns back on whenever the
view reaches the end. Pins wait for the gesture to end, so nothing moves the view under a finger.
Any detached page view shows the existing Scroll to latest control.
…inger

The phone chat page holds re-pins while a finger is on the list, and only a
touchend that React saw let them resume. A thumb resting on the streaming row,
replaced mid-touch, ended on the removed element, so pins stayed held for good.
Listen for each list touch's end on the element it started on, which the
browser keeps targeting after removal, and derive "touching" from those.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing this in favour of three smaller stacked PRs that rebuild the fix from current main:

Why this PR was superseded. #28413 made the phone chat keep your place while you read older messages, and on the web-page version of the phone chat (over-the-air builds) it brought several bugs: a small nudge up silently stopped auto-scroll with no "Scroll to latest" arrow, switching chats kept the last chat's scroll state, very long chats stopped following on every message at 2,000 messages, and loading older messages could jump past your place. This PR fixed those over six review rounds, but final iPhone testing found a new problem: after older messages loaded at the top, the chat could freeze and stop scrolling until you left it.

The review traced every one of these bugs to one cause. On that page, the list doesn't keep your place, follow new output, or load older messages by itself, so Orca did all three by hand around a single number, the list's scroll position. Orca's own scroll writes, iOS's bounce and momentum, and the "did the reader scroll away?" check all touched that number and kept misreading each other. Patching each case inside this PR kept producing the next one, so Brennan chose to rebuild it as the three focused PRs above. Each removes one part of that cause and can land or be reverted on its own.

The branches of this PR stay until those three merge.

@brennanb2025
brennanb2025 deleted the brennanb2025/mobile-chat-scroll-follow-fixes branch October 19, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant