Skip to content

fix(chat): keep the open side panel mounted across a fold or an unfold - #40358

Open
yashl wants to merge 1 commit into
kirodotdev:mainfrom
yashl:fix/fold-continuity-side-panel
Open

yashl wants to merge 1 commit into
kirodotdev:mainfrom
yashl:fix/fold-continuity-side-panel

Conversation

@yashl

@yashl yashl commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

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

  • Iframe content in the panel (an app frame, a web preview). Moving an iframe in the page reloads it in every browser, so the frame still starts over, as it does on main.
  • Where the panel sits beside a reported fold. That is the foldable RFC's later phase.
  • Any change to the panel's layout, size rules or animations.
  • The sessions list's focus after a move. Its list already moved this way on main, and its lane keeps its own scroll memory.

What changed (motivation → approach → change)

The page rendered two separate SidePanel elements, 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.

Piece Change
ChatSidePanels.tsx One SidePanel, 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.tsx Both halves of the sessions list's mechanism move out of SessionsSidebarChrome.tsx so both owners share them: useKeptPaneHost makes the kept host, and AdoptPaneHost puts it in the surface on screen. The slot now reports when it mounts and unmounts. A host made with keepScrollAndFocus (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.ts The on-screen check and the trackpad slide find the panel by its root test id (sidePanelIn), 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.

  • Scroll position. On main each fold mounts a new panel, so file and artifact tabs take their remembered offset back from useScrollMemory and 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.
  • Focus. On main a fold destroys the focused field, so the focus is lost. Now the field survives the move, and the host focuses it again when nothing else has taken the focus in between. A field the person left for another place is not focused again. The panel also mounts only once a surface holds its host, so what runs on mount (a terminal taking the focus, the active tab scrolled into view, the activity view following its newest entry) runs with the panel on the page.
  • Dismissal. The phone overlay closes by the swipe bound on the chat container (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 are display: contents boxes 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 way ChatSidePanels moves 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.

After kept host without the put-back kept host with it (this head)
a fold box at 0, log at its top, focus on the page box at 500, log at its end, focus in the field
an unfold box at 0, log at its top, focus on the page box at 500, log at its end, focus in the 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 SidePanel instances across a form switch changes, from two to one.

Removes nothing: no prop, key, route or stored value is dropped. AdoptPaneHost keeps its name and behaviour and gains an optional callback. useKeptPaneHost gains an optional keepScrollAndFocus, 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 real ChatPage with the real useIsMobile and 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, and useKeptPaneHost keeps one detached host for its owner's whole life. With keepScrollAndFocus: 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's focusout during 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 no scroll, 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.tsx also 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' and expected '' to be 'use the staging account', the two that look the panel up with sidePanelIn fail because main has no such helper, and the scroll and focus test fails with expected 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:

  • the mount condition: mounting while no surface holds the host, either of its two parts alone, keeping the panel mounted once the store no longer wants it, and never arming the part that keeps it through a form switch;
  • the put-back: no put-back, an end-following box put back at its old offset, recording a scroll read off the page, keeping a field the person left, dropping the field on every 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);
  • the slide or the health check reading the column's first child instead of the panel root, and a kept host that is a new element on every render.

AdoptPaneHost.test.tsx and ChatPage.sidePanelFold.test.tsx passed 20 runs in a row with KIROCREW_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 minimal fixture) 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.

Width main 5239591 this change on that main
951, after picking Approvals Approvals
382, after the fold Overview (reset) Approvals
951, after the unfold Overview Approvals

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 with sidePanelIn is not a function)
After (head d3fb230): npx vitest run src/test/ChatPage.sidePanelFold.test.tsx -> 8 passed
Cleanup: 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.

main, folded to 382

After (head): Approvals is still picked.

head, folded to 382

Related Issues

Closes #40065

Other open PRs edit some of these files. #33546, #37155 and #38238 edit ChatSidePanels.tsx. #37890 and the draft #38716 edit ChatPage.trackpadSwipe.test.tsx, and #38716 also edits chatTrackpadSwipe.ts. #15957 and #21614 edit SessionsSidebarChrome.tsx. Of these, only #38238 conflicts with this branch, in ChatSidePanels.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

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

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.
@yashl
yashl requested review from a team and KiroCrewCaptain as code owners November 21, 2026 07:53
@yashl
yashl requested a review from dodgeblaster November 21, 2026 07:53
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Nov 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat side panel loses what was typed in it when the window crosses the phone breakpoint (folding or unfolding a foldable)

1 participant