Skip to content

Highlight code while it streams, so settling doesn't pop - #203

Merged
milind-soni merged 1 commit into
mainfrom
feat/streaming-highlight
Aug 17, 2026
Merged

Highlight code while it streams, so settling doesn't pop#203
milind-soni merged 1 commit into
mainfrom
feat/streaming-highlight

Conversation

@milind-soni

Copy link
Copy Markdown
Owner

In plain terms

After a streamed reply with code finished, its code blocks rendered plain for a beat and then "popped" into color — the last visible rough edge at stream end (follow-up to #202).

Why

While streaming, CodeBlock skipped shiki entirely and never wrote the highlight cache. The settled bubble is a fresh component instance, so its blocks mounted plain, then async shiki swapped highlighted HTML in.

The fix

Highlight during streaming, debounced: a block whose content has held still for 250ms (the fence is very likely complete) tokenizes and caches. The debounce is the effect lifecycle itself — every content change re-runs the effect and the cleanup clears the pending timer, so a growing block never tokenizes per token. The settled bubble then mounts straight from cache: no pop. Partial fences may cache under their own content hash — harmless (distinct keys, evicted by the existing cap), and the header comments now state the new invariant honestly.

Non-streaming behavior is unchanged.

Test plan

  • pnpm typecheck clean; full pnpm vitest run green (736 passed)
  • oxlint adds no findings over base (the one hit is pre-existing, verified via stash)
  • Reviewer eyeball: stream a reply containing a fenced code block — it should colorize ~250ms after the block stops growing, and stay stable through the end of the stream

🤖 Generated with Claude Code

While a reply streams, a code block now highlights after its content has
been unchanged for 250ms instead of waiting for the stream to settle.
The result is written to the content-hashed highlight cache, so the
settled bubble (a fresh component instance) mounts highlighted from
cache instead of popping from plain <pre> to Shiki output a beat later.

The debounce rides the effect lifecycle: every content change re-runs
the effect and its cleanup clears the pending timer, so a growing block
never tokenizes per token. Partial fences may cache under their own
hash — harmless, since the final content gets a distinct key and the
cap evicts strays. Non-streaming rendering is unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@milind-soni, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 35 minutes

Limit details: You’ve used all 3 included reviews currently available under your plan.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: be6fe4d0-dcbb-4e91-88c5-b287e2592712

📥 Commits

Reviewing files that changed from the base of the PR and between 8b95206 and 47e9fbf.

📒 Files selected for processing (1)
  • src/components/ChatMarkdown.tsx

Comment @coderabbitai help to get the list of available commands.

@milind-soni
milind-soni merged commit ce61a99 into main Aug 17, 2026
5 checks passed
@milind-soni
milind-soni deleted the feat/streaming-highlight branch August 17, 2026 20:31
kargnas added a commit to kargnas/OpenMausBot that referenced this pull request Aug 17, 2026
main의 milind-soni#207(긴 대화 Show-earlier), milind-soni#206(Cmd+K 팔레트), milind-soni#204(iOS
컴패니언), milind-soni#203(스트리밍 코드 하이라이트) 병합. 충돌은 테스트 파일의
node:fs import union뿐이었다.

Tested: pnpm typecheck, pnpm vitest run (94 files, 905 passed, 8 skipped)

Confidence: high
Scope-risk: narrow
Reversibility: clean
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