Repository navigation
Studio: keep code colour while scrolling long chats - #14242
Merged
Merged
Conversation
Go back to deferred fence highlighting as the default, as #13919 first proposed, and drop the scrollbar thumb guard for the line window. With the line window, every line outside it rendered as plain text, and the guard held it during a thumb drag, so dragging the scrollbar turned the code being read into raw text until the thumb was released. Deferred highlighting keeps the colour of everything already highlighted while scrolling and does not stall the drag. The line window stays reachable through the existing override.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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
pushed a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Oct 19, 2026
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Nov 7, 2026
…oured while scrolling (unslothai#16865) Same capped, scrollable chat code blocks as unslothai#16864, plus colour while scrolling: code blocks no longer show as plain text during a fast scroll and colour in only after you stop. This is one of two alternative PRs; pick one. ## What this adds on top of unslothai#16864 Since unslothai#14242 made `defer` the default fence mode, colouring waits until input has been quiet for 300 ms, so during a fast scroll every block that comes into view is plain text and colours about 0.9 s after you stop. With blocks capped, the work a block needs when it comes into view is bounded (the lines in its box, at most one batch per frame), so it no longer has to wait: - `fence-highlight-queue.ts`: an entry can be marked as allowed to run mid-scroll; the queue runs those ahead of older ones that still wait for quiet. - `schedule-idle-task.ts`: `nonScrollInputQuietIn()` ignores wheel, scroll and touchmove (clicks, keys and pointer holds still count). - `code-fence-defer.tsx`: reaching a block, and colouring the lines in view inside a capped block, are marked mid-scroll safe. Everything else, including the rest of a long block and grammar warm-up, still waits for quiet. Holding a scrollbar thumb or a text selection in a block still blocks colouring, as before. Everything else (cap, Expand code, stable scrollbar gutter, in-view colouring, streaming follow, header with code icon and language name, action order and size, hover-only sideways scrollbar, per-block word wrap, line wrap and code icons) is identical to unslothai#16864. ## Performance Headless Chromium against a running Studio, same seeded chats as unslothai#16864, fast wheel scroll (200 ticks): | | main | unslothai#16864 | this PR | | --- | --- | --- | --- | | Frames showing an uncoloured block while scrolling (normal chat) | 448 of 604 | 214 of 613 | 0 of 611 | | Time from stopping until every visible block is coloured | about 0.9 s | about 1.6 s | about 10 ms | | Page scroll, long code chat, CPU 4x: frames over 50 ms | 0 | not measured | 0 | | Page scroll, long code chat, CPU 4x: total stalls | 0 s | not measured | 0.18 s | Opening a chat costs the same as unslothai#16864 (about half of main's stall time at 4x CPU). ## Verification - `npm run typecheck`, `npm test` (15,001 pass), `npm run build`. - On top of unslothai#16864's tests: a queue test that a mid-scroll entry runs while older work waits for quiet, the updated `blocked` shape check, and `noteInput` accepting a call without an event. - In a local Studio: blocks stay coloured during a fast page scroll and while scrolling inside a long block. - Live streaming with Gemma 4 E2B: the block followed its last line to the end and stayed there after the stream finished; after a 150 px scroll up mid-stream it held its place through the rest of the stream and the swap to the finished block. ## Not tested here - Same as unslothai#16864: Safari, Firefox and the Desktop webviews. - Frame timing while scrolling inside a single long block (colour was checked, stalls were not timed). ## Screenshots Same scripted reply with a 93-line Python block streamed into main (left) and this PR (right), Chromium 1500x1000, message scrolled to its start. Main lays out all 1632 px of the block in the page; this PR caps it at 480 px, scrolls inside (following the end of the stream), and adds the header with the language, word wrap, Expand code, download and copy. The headless browser hides scrollbars.  --------- Co-authored-by: Unsloth <[email protected]> Co-authored-by: danielhanchen <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #13919. Since that merge, dragging the chat scrollbar over a long code block turns the code into plain text until the thumb is released. This goes back to the default @Sneakr proposed in #13919, so code that has been coloured stays coloured while scrolling.
Cause
#13919 shipped with the line window as the default and a guard that holds the window still during a scrollbar thumb drag. With the line window, every line of a large fence outside the window renders as plain text. While the thumb was held, the window did not follow it, so the code being read showed as raw text until release.
Change
SHIP_DEFAULTgoes back todefer: once a fence is coloured it keeps its colour while you scroll, and nothing is swapped during a drag, so the drag stays smooth.window.__UNSLOTH_DEFER_FENCE_HIGHLIGHT__ = "window").Measurements
Real Studio, production builds, a thread of ten Python fences of 280 to 3,200 lines. The middle of the 3,200-line fence was coloured first, then the scrollbar thumb was dragged back over it and held:
Measured with this default in #13919: a thumb drag over the large fence had 0 to 350 ms of long frames at 4x CPU throttle, against 4.2 s with the line window and no guard.
Trade-off: with
defer, every line already coloured keeps its spans, so a very long chat read end to end holds more DOM, and a theme change after such a read is slower (about 2 s at 1x on the test thread) than with the line window.Testing
Before and after
Same thread on main (BEFORE) and this PR (AFTER), each from its own production build, with the scrollbar thumb held still in the middle of the 3,200-line fence after the region had been coloured.