Skip to content

Reduce scrolling lag in long chats by bounding offscreen reply painting - #16782

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
Imagineer99:fix/bound-offscreen-reply-paint
Nov 6, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
Imagineer99:fix/bound-offscreen-reply-paint

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

Summary

Scrolling a long conversation can make the browser repeatedly paint replies far outside the viewport. This change gives distant assistant replies their own CSS paint boundary. A shared IntersectionObserver per chat scroller removes the boundary before a reply comes into view. Replies wider than their column keep their horizontal overflow, and print uses normal page layout.

Related to #16603. #16656 addresses typing latency. This PR addresses scrolling and can be reviewed independently.

Verification

The production build and the long-chat browser test passed on the submitted commit. The new CI assertions exercise scrolling a reply into and out of view, print layout, and horizontal access to an oversized reply.

I also compared production builds with and without the scrolling change on top of #16656 at 7def5eda. Both opened the same saved 600-message, 7.11-million-character conversation with two thinking panels expanded, code blocks, and LaTeX. The figures below are the median of three passes' 95th-percentile frame gaps while scrolling through the middle of the thread.

Windows renderer Before After
WebView2 25.0 ms 12.5 ms
Chrome (headless) 24.9 ms 8.4 ms

The WebView2 run used a local host for the Windows renderer. The packaged desktop app still needs a manual pass. Browser interaction checks covered find, text selection, message menus, thinking expansion, code highlighting, and print styles in Chrome, Firefox, and WebKit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T10:52:58.596620Z 583a086 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

… size

A reply bounded while far off screen is only re-evaluated when it crosses the observer margin.
If the chat column narrows or the font grows, it can overflow without another intersection
callback and keep its paint boundary, clipping its overflow. A shared ResizeObserver per
viewport now drops the boundary from any bounded reply that overflows horizontally; unbounded
replies skip the layout read.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 583a086820

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit that referenced this pull request Nov 6, 2026
…efore dragging it (#16909)

## Summary

`Chat UI Tests (chat)` keeps failing on unrelated PRs in the floating
monitor geometry step:

```
[ui] resize landed at 260x141 with limits {'minWidth': 256, 'maxWidth': 260, ..., 'inline': 'opacity: 1; left: 988px; top: 0px; ... max-width: 260px; ...'}
AssertionError: [ui] FAIL: resize width: expected 296, got 260
```

Seen on the staging runs for #16890 and #16782 today, with identical
numbers. The limits logging added in #16885 is what shows the cause, and
it is not the stale viewport limit #16861 and #16885 assumed.

`use-floating-panel-layout.ts` sets `maxWidth = constraints.width -
left`. With the 1280 px viewport and 16 px insets the constraint box is
1248 px wide, and `1248 - 988 = 260`. So during the resize the panel was
moved to the right edge, though the step had just dragged it to the top
left and the limits wait before the resize saw room for 296 px.

The sequence:

1. The active drag into the shrunken viewport's corner snaps the panel
back to its anchor, so its horizontal position is "right edge"
(`intent.left === null`).
2. At the 260 px viewport that anchor puts it at left 0. On
`set_viewport_size(viewport)` the next layout pass moves it back to the
right edge, but left 0 is inside the restored viewport too, so
`wait_for_box("viewport restore", is_inside)` can pass before that pass
runs.
3. `drag_monitor_to(0, 0)` then grabs a panel still at left 0 and drops
it at left 0. `finishDrag` only makes an axis absolute when the drag
changed it ("a null axis stays anchored to the far edge"), so the
horizontal anchor stays on the right edge.
4. The native resize fires the layout's `ResizeObserver`,
`placeAxis(null, maxLeft)` puts the panel at the right edge (left 988),
and the width is capped at the 260 px left there.

The component is doing what it is designed to do: a user cannot start a
drag in the frame between a window resize and the layout pass. Only the
test grabs it too early.

## Change

`tests/studio/playwright_chat_ui.py`, test only. After restoring the
viewport, wait for the monitor to stop moving (`wait_for_settled`, the
frame-polled helper `pointer_drag` already uses) before the `is_inside`
check and the drag. The layout pass runs within that wait and restarts
it if it moves the panel, so the drag starts from the panel's real spot.
The comment on the limits wait from #16885 no longer blames a stale
viewport limit.

## Testing

- The failing runs' logged limits match the sequence above exactly
(`left: 988px`, `max-width: 260px`, `1248 - 988 = 260`), on two runs on
different staging repos.
- `python -m py_compile tests/studio/playwright_chat_ui.py`.
- This PR's own `Chat UI Tests (chat)` run exercises the step. The
failure is a timing race, so a single green run cannot prove the fix by
itself; I will keep watching the staging runs after it lands.
@danielhanchen danielhanchen reopened this Nov 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@danielhanchen
danielhanchen merged commit a17436b into unslothai:main Nov 6, 2026
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 6, 2026
…16854)

Opening panels and scrolling long chats can stall WebKitGTK because
offscreen message content still participates in style and layout work.
For Linux threads with 100+ messages, park completed offscreen bodies
behind measured placeholders while retaining their React state. Restore
rich content for scrolling, focus, find, selection, and print. Also
reduce offscreen code highlighting and keep browser-panel constraints
stable during opening and closing.

Prevent blank chat frames while history loads or the native scrollbar
jumps. A transparent fixed-background sentinel synchronizes WebKitGTK
overflow scrolling with main-thread painting. Commit small history
batches and their anchor corrections in the same rendering frame, pause
loading during scrolling, typing, composition, and pointer interaction,
and hold message heights during thumb drags. Reuse the existing
measurement-free collapsible for tool panels to avoid repeated forced
layouts from closed disclosures.

Keep text stationary as history loads: preserve the compensated anchor
between batches so intervening reflows are included, and absorb
fractional inserted heights in a leading spacer under one pixel. WebKit
can then apply whole-pixel scroll corrections without repeatedly moving
the text between fractional positions.

Validation:

- Production build, frontend/test typecheck, and 87 focused
progressive-mount, autoscroll, and message-window tests pass on the
updated branch.
- Existing Chromium autoscroll smoke test passes. Earlier validation
also passed all 13 tool-activity scenes.
- Native Tauri / WebKitGTK 2.54.2: switched from the 300k-token copy to
the 600-message (~911k-token) thread and exercised wheel scrolling,
thumb reversals/release, and bottom-following during loading. After
native wheel motion ended, a fixed text range varied by 0.015625 px,
down from 2.234375 px before this change. The same bound held after
thumb release. Repeated the wheel run after incorporating the branch's
main merge.
- None of the 96 OS screenshots across these four loading runs captured
blank chat content. Earlier settled-drag checks kept the scroll range
fixed.
- Earlier native typing validation delivered all 40 keystrokes, paused
history loading throughout input, and measured at most 30 ms from input
to the second animation frame. Native Settings and browser-panel checks,
plus find, selection, and print restoration, also passed.

Full history still mounts progressively. Extremely fast drags through
complex replies can drop frames; these checks establish that the
reproduced periodic blanking and visible loading shake did not recur in
the tested sequences.

Related to unslothai#16603. This complements unslothai#16656 and unslothai#16782; message windowing
and the scrolling workaround are limited to WebKitGTK.

---------

Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants