Repository navigation
fix(mobile): open each chat at its newest message when switching chats - #29099
Conversation
The chat view stays mounted across chat tabs, so a reader's scroll in one chat carried into the next: it opened mid-transcript and not following. Reset follow intent and the page's history head when the chat changes, before paint, and keep view-wide state (Tools toggle, text size).
The page pin scrolled to the last reported content height, which after a chat switch is still the previous chat's, so a taller chat could paint one frame mid-history before its own height arrived. Pin to the scroller's live height instead.
Review status: ready for a merge decisionThe problem. On the phone, the chat view stays on screen when you move between chat tabs, and the "am I following the newest message?" state lived on that view instead of on the chat. If you scrolled up in chat A and then switched to chat B, B opened short of its newest message, with the jump-to-latest arrow showing, and new replies didn't scroll into view. The over-the-air phone page has had this since #28413 (shipped in 1.4.226), and the native app had it before that. What changes for you. Every chat you switch to, including one you come back to, opens at its newest message and keeps following new replies. Things that belong to the view (the Tools toggle, pinch-zoom text size) stay as you left them. Your old place in a chat isn't remembered per chat, before or after this change. Fixed during review
Deferred or disclosed
What was verified
Not verified
|
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
🧹 Nitpick comments: 1
mobile/src/session/use-mobile-native-chat-page-history.test.tsx: 1
23-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a scope-change case with overlapping row IDs.
The harness always passes the same
'chat'scope and never changes it after recording a head. The related view test changessendSurfaceId, but it switches froma1tob1; the previous head is absent, so an unscoped implementation also passes. Add a case where the new chat contains the previous chat's remembered head at a nonzero index.Suggested fix
- function Harness({ items }: { items: Item[] }): null { - history = useMobileNativeChatPageHistory(items, renderRow, 'chat') + function Harness({ items, scopeKey }: { items: Item[]; scopeKey: string }): null { + history = useMobileNativeChatPageHistory(items, renderRow, scopeKey) return null } - async function show(items: Item[]): Promise<void> { + async function show(items: Item[], scopeKey = 'chat'): Promise<void> { await act(async () => { if (renderer) { - renderer.update(createElement(Harness, { items })) + renderer.update(createElement(Harness, { items, scopeKey })) } else { - renderer = create(createElement(Harness, { items })) + renderer = create(createElement(Harness, { items, scopeKey })) } }) } + it("does not reuse a page head from another chat", async () => { + await show(rows('a', 'b'), 'chat-a') + await show(rows('x', 'a', 'b'), 'chat-a') + + await show(rows('p', 'a', 'b'), 'chat-b') + + expect(history?.listRows).toEqual(rows('p', 'a', 'b')) + expect(headerRows()).toEqual([]) + })
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
bfbe45e1-ea35-484d-881e-adcd1930ac11
📒 Files selected for processing: 5
mobile/src/session/MobileNativeChatView.test.tsmobile/src/session/MobileNativeChatView.tsxmobile/src/session/use-mobile-native-chat-page-history.test.tsxmobile/src/session/use-mobile-native-chat-page-history.tsxmobile/src/session/use-mobile-native-chat-tail-follow.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
#29099 took mobile/src/session/MobileNativeChatView.test.ts to 806 counted lines, over the 800-line test cap, so the phone app's lint fails on main. Move the four Stop and Stopping cases verbatim into MobileNativeChatView.turn-status.test.ts, which has the same setup, and put the listIds doc comment back above the function it describes.
ELI5
On the phone, if you scroll up in one chat and then switch to another chat, the new chat opens somewhere in the middle instead of at its latest message, and new replies don't scroll into view. After this change, every chat you switch to opens at its newest message and keeps following new replies, like it does when you first open it.
What Changed
The problem. The phone's chat view stays on screen (mounted) when you move between chat tabs; only the chat it shows changes. The "am I following the newest message?" flag and the scroll bookkeeping lived on that view, not on the chat. So in chat A, scrolling up turned following off, and switching to chat B kept it off: B opened at A's scroll position (native app) or at its oldest loaded message with the jump-to-latest arrow showing (the over-the-air phone page). Since #28413 (shipped in 1.4.226) the phone page has this too; the native app already had it.
User-facing change. Switching to a chat always ends at its newest message, following. On the over-the-air phone page it gets there after the same short climb every page open already has on
main: for about a tenth to a fifth of a second the new chat draws a little short and steps down through its last few screens while the list renders its rows in batches. Opening a chat for the first time does exactly this today; a follow-up PR makes the first drawn frame of any chat on the page its newest message. Things that belong to the view rather than to one chat stay as you left them: the Tools expand/collapse toggle and your pinch-zoom text size. This includes switching back: returning to a chat you had scrolled up in opens it at its newest message too, not at your old place (as when you first open a chat; your place isn't remembered per chat, before or after this change).Mechanism.
use-mobile-native-chat-tail-follow.ts: the hook now takes the chat's identity (scopeKey, the host + worktree + tab key the composer and turn disclosure already use). When it changes, a layout effect runs before paint, so the follow state never paints at the old chat's position: it clears the page's last-offset bookkeeping and does the same "jump to latest" a send does, which turns following back on, hides the arrow and pins to the end. Content that measures in afterwards keeps it pinned, because following is on. On the page, that pin scrolls to the scroller's live height, not the last height the list reported: right after a switch the reported height is still the previous chat's, so a taller chat would have painted one frame mid-history before snapping to the end.use-mobile-native-chat-page-history.tsx(page only): the remembered "row the list starts at" is now stored together with the chat it belongs to. Row ids such as the streaming bubble's repeat across chats, so an id alone could let chat A's history split leak into chat B.Why
Linked Issue
Follow-up to #28413 (shipped in 1.4.226).
Visual Proof
The phone chat page in Orca's Electron build on Windows, this PR (left) vs
main(right), with the agent still working in chat B.Scroll up in chat A, then switch to chat B: B opens at its newest message and keeps following, vs

mainopening it short of the end with the arrow showing and new output not followed.Switch back to chat A: A opens at its newest message, following, vs

mainopening it at the top of a short loaded window, short of the end. Neither build returns to where the reader left A; this PR goes to the newest message by design.Also checked on the iOS simulator (page and native app): both open at the newest message and follow, vs
mainopening at the top of the loaded history. Both surfaces still show one to four in-between frames on a switch (the pre-existing climb described above).Testing
One test in
MobileNativeChatView.test.ts: scroll up in chat A and expand Tools, switch to chat B; B pins to its end, has no jump-to-latest arrow, keeps following new content, and Tools stays expanded.One page test in the same file: after a switch, the pin goes to the new chat's live height, not the previous chat's reported height (it replaces the page resize test, which hit the same pin).
No local checks on this machine (shared machine policy); CI runs lint, typecheck and tests.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
Mobile only, no wire or host change, so mixed phone/host versions are unaffected. Same on SSH and local hosts: the chat identity includes the host.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)