Skip to content

fix(chat): let the list scroll to the end that is drawn, so a reopened chat lands at its end - #2720

Merged
devswha merged 4 commits into
mainfrom
fix/chat-virtual-reload-end
Nov 4, 2026
Merged

devswha merged 4 commits into
mainfrom
fix/chat-virtual-reload-end

Conversation

@devswha

@devswha devswha commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Change

scripts/chat-virtual-browser-qa.ts:81 (settleBottom after page.reload()) timed out intermittently on PR runners (#2621's rerun, twice in a row; #2644): the reopened chat ended about 54 px short of its end, and CI's failure screenshot shows Jump to latest. The test was right: a reopened chat took the reader for one who had scrolled away, with no input.

Caught with a debug build that logs every follow and scroll decision (it failed the first reload in 4 of 8 runs under load):

  1. On the reload the list's first landing is short of the end (its footer not measured yet), and the chat's followMeasured puts the view at the real end: max(measured 120061, scrollHeight 120115) - 900 = 119215.
  2. In the same frame the view is pulled up to 119161 = the list's own measured contentLength (120061) - clientHeight. LegendList's own scroll to the end is still on its way, and while one is (state.scrollingTo), its onScroll clamps any position past the end it has measured so far back to that end (clampScrollOffset). Its measure lags the transcript by 54 px there (the footer and some rows not measured yet).
  3. ChatView.onScroll sees a move up with no input, 54 px from the end (more than the 48 px layout allowance) over a transcript that did not shrink, and concludes the reader left the end: stick=false paging=true, Jump to latest. Nothing follows again. When the lag is under the allowance, the chat instead stays "following" short of the end, with nothing left to correct it (the local variant).

LegendList's end on the web can only lag what the browser shows (it measures what it renders, a frame or more late), so the fix is in the LegendList patch this repo already keeps (patches/@legendapp%[email protected], two hunks, plus a helper):

  • A helper finds the end of what is drawn: the bottom of the list content's children and of the rows inside the rows' wrapper (rows as tall as they are drawn, a header or footer not measured yet), relative to the scroll origin. It deliberately leaves out the room the list pads past its end for a frame while it holds rows in place, and a min-height under the content (the selection hold's room, fix(chat): keep the words under a selection held through a slow fold #2684). An earlier version used the scroller's scrollHeight, which includes that room, and made reply-comments-demo-regression.ts drag selections land on other words in 2 of 7 runs.
  • clampScrollOffset never clamps below that drawn end. This is what pulled the view up in the captured failure.
  • scrollToEnd adds what the list has not measured yet (the drawn end past its measured one) to its end offset, so its own target is the real end instead of re-landing short.

When the list's measure matches what is drawn (settled), both changes are no-ops; a larger measure (rows estimated taller than drawn) keeps the list's own value. No app code changes.

The test: chat-virtual-browser-qa.ts gains the case right after the reload step that timed out. A 100 px box drawn after the footer inside the list's content, which the list never measures, makes its end lag the transcript's by more than the layout allowance (as an unmeasured footer and rows did in the captured failure), and a view a pixel shorter makes the chat follow its end and the list scroll to its own. The chat must end at the end, still following, with no Jump to latest. On main it ends 61 px short in every frame from the second on ({"gaps":[101,100,61,61,...]}); with this change it ends at 0.

Validation

  • chat-virtual-browser-qa.ts with the new case: origin/main (with fix(chat): keep the words under a selection held through a slow fold #2684) fails 2/2 at the new case (61 px short in every frame from the second on); this branch passes 4/4 (all four width/theme passes). The case lags the list's end twice: a box after the footer, and a box past the rows' wrapper (a row drawn taller than measured), which the review head 735a121 failed 2/2.
  • reply-comments-demo-regression.ts (drag selections, which the earlier scrollHeight version broke): 10/10 on main; on this branch 10/10, and 6/6 again on the final head 74b4389 (with turn-end 4/4, chat-history and local-send-follow passing, check fast ok).
  • The original reload timeout reproduces only on a loaded machine (about once in a few hundred reloads on this PC, 2 of 2 attempts on ci(windows): run the Claude command history tests on native Windows #2621's runner), so its before/after rests on the captured trace above and the deterministic case.
  • Merged with main (fix(chat): keep the words under a selection held through a slow fold #2684's selection hold also leans on the list's scroll): chat-selection-turn-end-demo-regression.ts 6/6 on this branch.
  • Adjacent browser scripts on this branch, all pass: chat-history-browser-qa.ts, chat-local-send-follow-demo-regression.ts, chat-quote-selection-end-regression.ts, chat-scroll-padding-regression.ts, chat-select-quote-demo-regression.ts, chat-selection-copy-regression.ts, chat-working-line-demo-regression.ts, chat-no-rewind-demo-regression.ts, reply-comments-demo-regression.ts, chat-gjc-streaming-browser-qa.ts. Runs were capped at 4 at a time with one shared demo build per variant.
  • The patch applies with a clean bun install from an empty cache and reproduces the tested file byte for byte; fix(chat): keep the words under a selection held through a slow fold #2684's react.d.ts hunk is kept; bun.lock is unchanged.
  • bun run check fast.
  • Not run: bun run check full, the Mac and Windows lanes (no platform code changed).

Changelog: changelog.d/chat-reopen-lands-at-end.md (Fixed).

devswha and others added 3 commits November 4, 2026 11:16
… the one it measured

A reopened chat could end short of its end and take the reader for one
who scrolled away (chat-virtual-browser-qa.ts:81 timing out on #2621 and
#2644, Jump to latest showing). Caught on a reload: while its own scroll
to the end was on its way, LegendList clamped the view to the end it had
measured so far (the footer and some rows not measured yet, 54 px short),
a move up with no input that ChatView reads as the reader leaving.

The LegendList patch now never clamps a scroll below the end the browser
allows, and a scroll to the end adds what the list has not measured yet.

chat-virtual-browser-qa.ts gains the case: a footer margin the list never
measures makes its end lag by more than the layout allowance; the chat
must still land at the end, following.

Co-authored-by: sisyphus-dev-ai <[email protected]>
… height

The scroller's scrollHeight includes room the list pads past its end for
a frame and the selection hold's min-height, so the clamp and scrollToEnd
could aim into it: reply-comments-demo-regression.ts drag selections
landed on other words in 2 of 7 runs. The end is now the bottom of the
list content's children (rows as drawn, a header or footer not measured
yet). reply-comments 10/10, as on main.

The chat-virtual case makes the list's end lag with a box drawn after the
footer (as an unmeasured footer does) instead of a margin, which is not
drawn content. Changelog fragment added.

Co-authored-by: sisyphus-dev-ai <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 9 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between a6e9143 and 74b4389.

Files selected for processing: 3
  • changelog.d/chat-reopen-lands-at-end.md
  • patches/@legendapp%[email protected]
  • scripts/chat-virtual-browser-qa.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Review (Codex, reproduced): rows sit inside a wrapper as tall as the
list's measured total, so a row drawn taller than measured reaches past
it without growing it; the drawn end now counts the rows inside it too.
Review (omo): scrollToEnd's unmeasured part no longer clamps the measured
end at zero first, which undercounted it when the measured content is
shorter than the view.

The chat-virtual case also makes the list's end lag past the rows'
wrapper (fails on the previous head), and waits until the view is at the
end for three frames instead of a fixed frame count.

Co-authored-by: sisyphus-dev-ai <[email protected]>
@devswha

devswha commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Review round on 735a121 (omo: CLEAR; Codex gpt-6.1-terra xhigh: REQUEST_CHANGES, no HIGH). Fixed in 74b4389:

  • MEDIUM (Codex), reproduced: the drawn end measured only the content's direct children. Rows sit inside a wrapper as tall as the list's measured total, so a row drawn taller than measured reaches past it without growing it. The helper now counts the rows inside that wrapper too (parked containers sit at -1e7 and cannot raise it). The QA case gained a second lag, a box past the rows' wrapper: it fails 2/2 on 735a121 (stuck 21 px short) and passes now.
  • MEDIUM (omo, from its Codex pass): scrollToEnd's unmeasured part clamped the measured end at zero first, undercounting it when the measured content is shorter than the view. Now max(0, drawnMax - (contentSize - scrollLength)).
  • LOW (omo): the QA sampler waited a fixed 12 frames; it now waits until the view is at the end for three frames (bounded), checking every frame that Jump to latest never shows.
  • LOW (omo), noted: the helper reads the bounding boxes of the content's children and the pooled rows (bounded by the pool) while a list scroll is in flight; left as is.

Validation on 74b4389: chat-virtual-browser-qa.ts 4/4 (origin/main fails at "after the footer", 735a121 at "past the rows"); reply-comments-demo-regression.ts 6/6; chat-selection-turn-end-demo-regression.ts 4/4; chat-history-browser-qa.ts, chat-local-send-follow-demo-regression.ts pass; bun run check fast ok. Runs capped at 4 at a time.

CodeRabbit: see its status on this PR; the omo and Codex reviews stand in if it was skipped or rate-limited.

@devswha

devswha commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Reviews at 74b4389: omo CLEAR; Codex (gpt-6.1-terra xhigh) REQUEST_CHANGES on one test-only MEDIUM, no HIGH. Per the one-more-round rule this PR stops here; remaining notes, none blocking:

  • Test timing (Codex MEDIUM, static; omo LOW, unreproduced): the new QA case treats three frames at the end as the list's scroll having landed; a list scroll that waited longer (it can wait for layout to settle) would land after the check. In the runs here the short landing shows from the first sampled frame (origin/main [61,61,…], 735a121 [21,21,…]) and the case failed every time on both. A follow-up can wait for the list's own scroll to finish.
  • LOW (omo), reproduced, no visible symptom: with content shorter than the view, scrollToEnd's unmeasured part now counts the empty space too, so the list records a scroll offset of 40 the browser cannot reach (the view stays at 0); it settles once the content outgrows the view. Possible tightening: subtract max(0, contentSize - scrollLength), as clampScrollOffset does.
  • LOW (omo), noted: the drawn-end helper reads the bounding boxes of the content's children and pooled rows while a list scroll is in flight (bounded by the pool).

CodeRabbit skipped this PR; the omo and Codex reviews stand in.

@devswha

devswha commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Merge note: CodeRabbit skipped this head; merged on the omo review (CLEAR at 74b4389), Codex Terra (one unreproduced test-timing MEDIUM, noted above), a deterministic QA case that fails on main, and green required checks.

@devswha
devswha merged commit ceb360d into main Nov 4, 2026
20 of 26 checks passed
@devswha
devswha deleted the fix/chat-virtual-reload-end branch November 4, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant