A transcript can look fine in a demo and still make it impossible to read an earlier answer. Start a response long enough to overflow its panel, scroll up one screen, and leave your hands off the keyboard while another sentence arrives. Where does the first line you were reading end up?
Give the reader control of following
For a conventional top-to-bottom scroll container, track two states. In following, appending a chunk may move the viewport to the end. In detached, an append leaves scroll position alone. Both states continue rendering the new text. The distinction matters when an image loads or code wraps after the chunk has already been inserted.
| Event | Prior state | Next action |
|---|---|---|
| New chunk | Following | Render, then align the panel with the bottom |
| New chunk | Detached | Render without scrolling |
| Reader scrolls away from the end | Following | Detach |
| Reader returns to the end or activates “Jump to latest” | Detached | Resume following |
Measure the remaining distance using scrollHeight - clientHeight - scrollTop. A small tolerance is needed because the first two values are rounded and the last can be fractional. A larger interaction threshold, such as 24 CSS pixels, is a design choice. Record whether the panel was following before the append. Measuring only after an append can mistake an unusually tall chunk for a reader scrolling away. This calculation needs adapting for a reversed layout or a virtualized list.
Check the viewport and keyboard focus separately
Use a real button for “Jump to latest” and keep its accessible name stable. Button placement matters when the transcript already contains links and controls. Decide where focus belongs if activation hides the button. A focused control disappearing can disturb keyboard navigation even when scroll position is correct.
Try a slow stream, a tall late-loading image and keyboard-only navigation. While detached, record the visible line before and after each update. While following, check that the latest line comes into view. Try reduced-motion settings and a screen reader separately; the table predicts application state, not a particular assistive technology’s reading position.
The browser’s rounding behavior is documented in the scrollHeight reference.
This article was created with AI assistance.
Top comments (0)