Thread chat auto-scroll
The message list (.thread-chat-messages) follows the conversation through
src/MeshWeaver.Blazor.Chat/ThreadChatView.razor.js → attach(container):
- On send,
ThreadChatViewcalls the handle'sfollow(). The list scrolls to the new message, and the reply is followed, whatever the reader had scrolled to before. - While a reply streams, a MutationObserver follows every new node and every streamed character, as long as the reader is following, meaning they are within 120px of the bottom.
- A reader who scrolled up is left where they are until they scroll back near the bottom or send.
The defect this fixes (reported 2026-12-01, a thread page in Chrome)
After a send the viewport did not move. The new user bubble showed only as a sliver above the input panel, and the reply sat behind it.
The old module released the stick whenever a scroll event found the list more than 120px from its bottom. But the list's viewport also shrinks under the reader, because the composer below it auto-grows as a message wraps. Measured at 1300×700: typing a two-line message took the list from 394px to 261px high. The browser answered with a scroll event of its own (scroll anchoring nudged scrollTop 839 → 835), the distance from the bottom jumped from 0 to 133px, and that read as "the reader scrolled up". From then on nothing was followed.
Now:
- A ResizeObserver keeps a following reader at the bottom when the viewport resizes. Its callback runs after layout and before the next frame's scroll event.
- A scroll event releases the stick only when scrollTop went down while the viewport kept its height.
- A send re-engages the stick explicitly (
follow).
Tests
clients/react/src/controls/threadChatAutoScroll.test.tsruns in CI. It drives the real module in a small browser model: composer growth keeps following, a reader who scrolled up is not yanked, scrolling back re-engages, andfollow()on send. The growth andfollowcases fail against the old module.src/MeshWeaver.Portal.E2E.Test/ChatAutoScrollTest.cstests the real portal. It sends five long messages and checks that the newest bubble is visible above the composer each time. It then checks that a reader who scrolled to the top stays there while typing, and that a send brings them back down.