Highlight code while it streams, so settling doesn't pop - #203
Conversation
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>
|
Warning Review limit reached
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. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Comment |
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
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 typecheckclean; fullpnpm vitest rungreen (736 passed)oxlintadds no findings over base (the one hit is pre-existing, verified via stash)🤖 Generated with Claude Code