Repository navigation
Conversation
The chat page's side panel is drawn by one of two surfaces: the shell's activity column in the desktop form, and an overlay over the chat in the phone form. Each surface rendered its own SidePanel, so a switch between the two forms (a book-style foldable folding from its 951 px inner display to its 382 px outer display, or a window resized across 768 px) unmounted the panel and mounted a new one. Anything the panel held only in its own state was lost, such as an answer typed into a Dashboard tab's question card. ChatSidePanels now renders a single SidePanel into a kept host element, and whichever surface is showing adopts that host. The sessions list already worked this way, so its two halves, the kept host (useKeptPaneHost) and the slot that adopts it (AdoptPaneHost), move out of SessionsSidebarChrome into components/ and both owners share them. The panel mounts once a surface holds the host, so its first effects (following the newest activity, revealing the active tab, a terminal taking the focus) run on the page. It then stays mounted while a surface holds the host or the store wants it, so a closing column and a sliding overlay keep their exit animations. A browser puts a box that moves to a new parent back at its top and sends the focus to the page. A host made with keepScrollAndFocus records each box's scroll offset and the focused field as they change, and each adoption puts them back. The side panel opts in. The sessions list does not: its lane anchors its offset to a row, and a pixel offset put back first would be recorded over that anchor. The health check and the trackpad slide find the panel by its root test id instead of the column's first child, since the host now sits in between.
Open
5 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Motivation
Goal: An open side panel keeps what the person typed or picked in it, where it was scrolled and which field had the focus, when the chat page switches between its phone and desktop forms, as it does when a foldable folds or unfolds.
On a book-style foldable the same tab moves between the desktop form (the inner display, 951 px) and the phone form (the outer display, 382 px). The desktop form draws the side panel in the shell's activity column and the phone form draws it as an overlay over the chat. Each switch threw the panel away and built a new one, so an answer typed into a Dashboard tab's question card, or the Questions/Approvals segment picked there, was gone after the fold. Any browser shows the same thing when the window is resized across 768 px.
Why it matters
A foldable is folded and unfolded many times while reading one chat, and a half-written answer to an agent's question is the input that costs the most to lose. The chat composer and the side chat already keep their drafts across this switch, so the side panel was the one surface that silently dropped work.
Not a goal
What changed (motivation → approach → change)
The page rendered two separate
SidePanelelements, one per form, so React mounted a new panel on every form switch. The sessions list already solved the same problem with a kept host element that whichever surface is showing adopts. This change gives the side panel the same mechanism, shared rather than copied.Moving a panel has costs of its own. A browser puts a box that moves to a new parent back at its top and sends the focus to the page, and a panel mounted before any surface holds its host runs its first effects off the page. So the side panel's host records each box's offset and the focused field as they change and puts them back after each move, and the panel mounts only once a surface holds the host.
ChatSidePanels.tsxSidePanel, portaled into a kept host. The desktop column and the phone overlay each adopt the host instead of rendering their own panel. The panel mounts once a surface holds the host, then stays mounted while a surface holds it or the store wants it, so a closing column and a sliding overlay keep their exit animations.components/AdoptPaneHost.tsxSessionsSidebarChrome.tsxso both owners share them:useKeptPaneHostmakes the kept host, andAdoptPaneHostputs it in the surface on screen. The slot now reports when it mounts and unmounts. A host made withkeepScrollAndFocus(the side panel's) records scroll offsets and the focused field, and each adoption puts them back. The sessions list's host leaves it off: its lane anchors its offset to a row (useLaneScrollMemory), and a pixel offset put back first would be recorded over that anchor.utils/sidePanelHealth.ts,chatTrackpadSwipe.tssidePanelIn), since the host now sits between the column and the panel. The slide's positioning classes target the same root.The panel's props are unchanged except
canDockBottom, which now follows whether the shell column is in use, the same split the two separate elements had.Focus, scroll position and dismissal on the phone form
These are the three things #40065's triage asked a reviewer to check.
useScrollMemoryand the activity view scrolls to its newest entry. One panel that moves gets neither from a mount. Its host records each box's offset as it scrolls and puts it back after each move, and a box that was at its end (the activity log) stays at its end when the new width changes its height.useDrawerSwipe), by the panel's close button (onClose={toggleAct}) and by the store. None of these reads where the panel's React element sits. The host and its slot aredisplay: contentsboxes inside the overlay, so a touch on the panel still reaches the chat container through the overlay, and the swipe's checks for an element that owns the touch (a horizontal scroller,touch-action: none, a modal layer, a focused field) meet nothing new. A test drives a swipe from the panel's content and checks that the overlay closes.A browser check of the real
AdoptPaneHost, bundled with React and moved the wayChatSidePanelsmoves it: on a fold the column's slot leaves the page first and the overlay adopts the host a moment later; on an unfold the column adopts the host while the overlay still holds it. The panel holds a box scrolled to 500 px, an activity log scrolled to its end, and a focused text field.The results are the same in WebKit 26.0 and Chromium 145.
Backwards compatibility
Compatible: the panel renders the same props in the same surfaces; only the number of
SidePanelinstances across a form switch changes, from two to one.Removes nothing: no prop, key, route or stored value is dropped.
AdoptPaneHostkeeps its name and behaviour and gains an optional callback.useKeptPaneHostgains an optionalkeepScrollAndFocus, off by default, so the sessions list's host is made and moved as before.Tests
website/src/test/ChatPage.sidePanelFold.test.tsx(new) renders the realChatPagewith the realuseIsMobileand resizes it. A panel stub holds a draft in its own state and a scroll box that keeps its offset only where it is, as a browser's does. It pins: the draft survives 951 -> 382 -> 951 and 382 -> 951 -> 382 with one mount; it survives 669 <-> 382 within the phone form; the health check and the slide find the panel in the column it moved to; the panel still unmounts once it is closed, on either form, after the column's exit animation; the panel is on the page each time it mounts; the scroll offset and the focus come back after a fold and an unfold; a swipe that starts on the panel still closes the phone overlay.website/src/test/AdoptPaneHost.test.tsx: the slot's mount callback fires once on mount and once on unmount, anduseKeptPaneHostkeeps one detached host for its owner's whole life. WithkeepScrollAndFocus: the offset and the focus come back after a direct move (an unfold) and after a move with a gap (a fold); a scroll read while off the page is not recorded; a box at its end stays at its end when its height changes; a field the person left is not focused again; a field whose focus something else took during the move is forgotten; Chromium'sfocusoutduring a move does not drop the field. A host made without it, as the sessions list's is, puts nothing back.website/src/test/browserScrollModel.ts(new): the browser scroll box both files use. happy-dom keeps a box's offset wherever it moves and fires noscroll, so a test of the put-back could not fail without it.ChatPage.trackpadSwipe.test.tsx,ChatPage.responsivePanel.test.tsx,useSidePanelHealth.test.tsx: the panel stub carries the root test id, and the column assertion reads the column instead of the panel's direct parent.useSidePanelHealth.test.tsxalso measures a panel nested in the kept host's box-less wrappers, the way the column now holds it.Red on main 5239591 (the new fold test file run against main's code): 5 of its 8 tests fail. The two draft tests fail with
expected '' to be 'ship it after the canary'andexpected '' to be 'use the staging account', the two that look the panel up withsidePanelInfail because main has no such helper, and the scroll and focus test fails withexpected false to be true. The other three pass on main and guard what moving the panel could break: the phone-form widths, mounting on the page, and the dismissing swipe.Mutations, each caught by at least one test:
focusout, taking the focus back from whatever has it, keeping a field that was not focused again, every host recording whether it opted in or not, the side panel not opting in, and the kept host claiming the touch (touch-action: none);AdoptPaneHost.test.tsxandChatPage.sidePanelFold.test.tsxpassed 20 runs in a row withKIROCREW_ACT_STRICT=1. With the health and responsive-panel tests they passed shuffled runs with seeds 4242, 7 and 91119.Proof: not provable -- frontend test (prove.py runs Python only)
Manual verification
Playwright WebKit against an isolated gateway (the
minimalfixture) built from each tree, desktop-mode browser: open the starter chat's side panel on the Dashboard tab at 951 x 700, pick Approvals, resize to 382 x 700, then back to 951 x 700.The scroll and focus check is the browser check under Focus, scroll position and dismissal. Not checked on a physical foldable.
Real-machine verification
Machine: a Linux x86_64 workstation, 64 vCPU / 123 GB, Node 22.11.0
Before (main 5239591):
npx vitest run src/test/ChatPage.sidePanelFold.test.tsx-> 5 failed, 3 passed (expected '' to be 'ship it after the canary'; the two lookups fail withsidePanelIn is not a function)After (head d3fb230):
npx vitest run src/test/ChatPage.sidePanelFold.test.tsx-> 8 passedCleanup: own computer
Screenshots / video
WebKit at 382 px, right after folding from 951 px with Approvals picked on the Dashboard tab.
Before (main): the tab is back on Overview.
After (head): Approvals is still picked.
Related Issues
Closes #40065
Other open PRs edit some of these files. #33546, #37155 and #38238 edit
ChatSidePanels.tsx. #37890 and the draft #38716 editChatPage.trackpadSwipe.test.tsx, and #38716 also editschatTrackpadSwipe.ts. #15957 and #21614 editSessionsSidebarChrome.tsx. Of these, only #38238 conflicts with this branch, inChatSidePanels.tsx; #21614 and #38716 already conflict with main. This change does not depend on any of them: #33546 keeps the panel in place through a reported fold, and its notes say a resize across 768 px with no fold still moves it, which is the case this change covers. I'll rebase this one if #38238 lands first.Sibling sweep
Swept: git grep -n "<SidePanel" -- website/src
Sibling: website/src/pages/members/MembersPageSidePanel.tsx -- not affected -- it renders one SidePanel element and only changes its wrapper's classes between forms
Pattern harvest
Not generalizable: the one other kept-host surface (the sessions list) already uses AdoptPaneHost and keeps its own row-anchored scroll memory, and the Members page renders a single panel; no third surface renders a component once per form.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits