Repository navigation
Studio: cap chat code blocks at a scrollable height and colour only the lines in view - #16864
shimmyshimmer wants to merge 7 commits into
Conversation
…d stop following only on the reader's own scroll
…bar gutter, and no fade over the scrollbar
…nly sideways scrollbar, smaller actions with Copy last, code-xml icon for source code The vertical scrollbar of long finished code blocks was clipped by the paint-contained wrapper; the wrapper now takes the body's bleed so the scrollbar paints.
|
@codex review |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 318819ec62
ℹ️ 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".
| const next = innerLineWindow(code.current, body); | ||
| if (next !== null && !lineWindowColoured(tokens, progress, next)) setScrolled((n) => n + 1); |
There was a problem hiding this comment.
Resume paused highlighting when expanding a code block
For a long completed block whose visible lines have finished highlighting, clicking Expand code leaves the newly revealed lines permanently uncoloured. This branch only listens for inner scroll events, and after expansion innerLineWindow() returns null, so even a resulting scroll event cannot restart the work. CodeBlockActions changes the wrapper attribute without rerendering the memoized FenceBody, and scrolling the outer chat does not trigger this listener either. Observe changes to the body's size or expansion state and resume highlighting when the cap is removed.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 983938a: while a capped block waits for a scroll, a ResizeObserver on the body also rechecks, and colouring resumes once the body stops scrolling internally (Expand code) or its view has uncoloured lines.
| ): void { | ||
| const following = useRef(true); | ||
| const mounted = tokens !== null && tokens.length > 0; | ||
| const key = `${language ?? ""}\n${source.slice(0, 200)}`; |
There was a problem hiding this comment.
Scope saved scroll positions to an individual code block
When two Python blocks share their first 200 characters—for example, repeated import boilerplate—the module-wide cache treats them as the same block, including across chats. Scrolling up in the first block causes a newly mounted, unrelated streaming block to restore that offset and set following.current to false, so it no longer follows its newest lines despite the reader never scrolling it. Use a stable message/block identity to transfer scroll state across the streaming-to-finished remount without sharing it between distinct blocks.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 983938a: only a body that streamed saves its place (on unmount), and only a finished body mounting within the next 2 s takes it, once. A new streaming block never restores, so it always starts following. Checked live: a reader's place survives the stream finishing, and a followed stream still ends at the bottom.
…nd a code block's scroll place only from a finished stream to its own remount
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 983938a5a8
ℹ️ 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".
| max-height: var(--unsloth-code-block-max-height, min(30rem, 55vh)); | ||
| overflow-y: auto; |
There was a problem hiding this comment.
Account for inner scrolling in the opt-in line window
When VITE_UNSLOTH_DEFER_FENCE_HIGHLIGHT=window is enabled, the new cap lets readers scroll beyond the highlighted lines without ever colouring the newly visible code. useLineWindow() still calculates contentTop from the stationary wrapper's bounding rectangle and uses the outer chat viewport; scrolling this body does not change either value, so its highlighting window remains near the beginning of the block. The new innerLineWindow() logic cannot compensate because useFenceHighlightLimit() explicitly excludes windowing mode. Update the windowing geometry to incorporate the body's scroll offset and viewport, or exclude that mode from the height cap.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: window is an opt-in build or runtime mode, not the shipped default (defer), and capped blocks in the default mode are coloured by the inner-view path. The line window is left as is for that experimental mode.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
…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]>
Long code blocks in chat used to grow to the full length of the code, so a 4,000 line answer made the page thousands of pixels taller and every line of it got coloured. Code blocks now stop at a fixed height and scroll inside, like ChatGPT, and only the lines you can see get coloured.
This is one of two alternative PRs. This one keeps main's behaviour of colouring after you stop scrolling. The alternative, #16865, also colours while you scroll.
What changes
min(30rem, 55vh)and scrolls inside (--unsloth-code-block-max-heightoverrides it). Printing removes the cap, so printed chats still show all the code.@hugeicons/core-free-icons4.4.0 does not ship yet, so they are traced intolib/hugeicons-derived.tsuntil it does.CodeXmlIcon. The plainCodeIconis unchanged.Performance
Headless Chromium against a running Studio, two seeded chats (8 blocks of 160 to 300 lines, and 4 blocks of 2,000 to 4,000 lines), CPU throttled 4x:
Shiki still tokenizes a whole block once when it comes near the screen; this saves the rendering of the coloured spans, not the tokenizing.
Verification
npm run typecheck,npm test(15,000 pass),npm run build.code-fence-body.test.ts,appearance-code-display.test.tsanddebug-log-export.test.tscover the cap and its print override, the in-view colouring, streaming follow, the per-block wrap override the icon stubs and the header language names.Not tested here