v2 chat: sending a message in a long virtualized thread jumps the view up before it returns to the bottom
What happens
In a v2 CopilotChat thread long enough to virtualize (more than 50 messages), sending a message makes the view jump up by roughly 10–20 messages. For a moment the screen can be mostly blank. It then glides back to the bottom over about 1.5 s.
It happened every time in 10 runs. It happens on main (measured at a789183a60) with both @tanstack/react-virtual 3.13.18 and 3.14.13, so it is neither #7488 nor the virtualizer version.
How it was measured
A local Vite page renders CopilotChat with an in-process agent. Its connect() replays a MESSAGES_SNAPSHOT of 80 messages whose heights range from one line to about 40 lines (a resumed thread), and run() streams a text reply in 40 ms chunks. Playwright drives Chrome, and a requestAnimationFrame recorder logs scrollTop, distance from the bottom, and each mounted row's viewport position on every frame.
After a fresh load (pinned to the bottom, rows 77–79 visible), type a message and press Enter. The lowest row index still visible after sending:
| Build | Runs | Lowest row visible |
|---|---|---|
main, react-virtual 3.14.13 |
5 | 57, 59, 59, 67, 71 |
| #7488 head, react-virtual 3.14.13 | 5 | 57, 57, 59, 69, 71 |
A typical run (#7488 head), visible row range over time:
before send 77–79
+50 ms 72–81
+100 ms 63–67
+200 ms 57–58
+400 ms 69–69
+800 ms 77–78
+1600 ms 79–81Starting from a view already scrolled to the bottom with scroll-to-bottom, the distance from the bottom grows from 0 to about 12,000 px within 200 ms of sending, while scrollTop stays the same for the first few frames.
Probable cause (not verified)
Rows that have never been measured are sized by estimateRowSize, which returns the mean height of the rows measured so far in the thread. When the new messages mount and get measured, that mean shifts. Every unmeasured row above the viewport changes size at once, and nothing compensates scrollTop for it. As far as I can tell, the virtualizer adjusts the scroll position when a measured item above the viewport changes size, but not when the estimate changes. The content above the view grows, the view shows older rows, and use-stick-to-bottom then scrolls back down.
Worth checking first:
- Freeze the estimate while pinned to the bottom, or only update it between threads.
- Compensate
scrollTopfor the change in estimated size above the first visible row when the mean changes.
Environment
@copilotkit/react-corev2 components, React 19.2- Chrome (Playwright 1.59), 900×800 viewport
- The harness (fake agent, Vite config, frame recorder) can be shared if useful.
Source: CopilotKit/CopilotKit