Skip to content

Studio: keep code colour while scrolling long chats - #14242

Merged
danielhanchen merged 1 commit into
mainfrom
studio-keep-code-colour-scrolling
Oct 19, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-keep-code-colour-scrolling

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

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_DEFAULT goes back to defer: once a fence is coloured it keeps its colour while you scroll, and nothing is swapped during a drag, so the drag stays smooth.
  • The scrollbar guard is removed. It only applied to the line window, which stays reachable as an override (window.__UNSLOTH_DEFER_FENCE_HIGHLIGHT__ = "window").
  • Everything else from Studio: fix chat scrollbar freezes on long code fences #13919 stays: chunked fence rendering, hoisted line colour, the progressive highlight queue, Thinking code colour, and the selection and cancelled-drag fixes.

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:

main this PR
visible lines coloured while the thumb moves 0 of 52 52 of 52
visible lines coloured while held still 0 of 52 52 of 52
visible lines coloured after release 52 of 52 52 of 52

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

  • Frontend: 12,791 tests pass, typecheck, production build, bundle check.

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.

Before and after: with the thumb held, main shows the code as plain text and this PR keeps its colour

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-10-19T11:47:39.727635Z e63fc5e Manual request
🔒 Security Review ⚠️ Failed 2026-10-19T11:45:11.079981Z e63fc5e PR opened
ℹ️ 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: e63fc5e717

ℹ️ 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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 19, 2026
@danielhanchen
danielhanchen merged commit 8de2de2 into main Oct 19, 2026
@danielhanchen
danielhanchen deleted the studio-keep-code-colour-scrolling branch October 19, 2026 12:32
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.

![Long code block, main vs this
PR](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16865/pr16865_before_after-cf032167d7d2.png)

---------

Co-authored-by: Unsloth <[email protected]>
Co-authored-by: danielhanchen <[email protected]>
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