🤖 fix: stop code-block highlight flashing while streaming#3480
Open
ammar-agent wants to merge 1 commit into
Open
🤖 fix: stop code-block highlight flashing while streaming#3480ammar-agent wants to merge 1 commit into
ammar-agent wants to merge 1 commit into
Conversation
Collaborator
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. ℹ️ 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". |
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
Fixes a bug where syntax highlighting flashes (plain ↔ colored, repeatedly) while a markdown code block is still streaming. The renderer now shows correct partial highlighting that grows in place: lines that are already finalized stay colored while only the still-growing tail renders as plain text.
Background
CodeBlockhighlights asynchronously via the Shiki worker, keyed on the fullcodestring. During streaming the typewriter growscodeon nearly every frame, so the async highlight is always a chunk behind. The previousgetCurrentHighlightedCodeBlockLinesgate did an exacthighlighted.code === codematch and returnednull(→ plain text) whenever the highlight was stale. The all-or-nothing fallback dropped the whole block back to uncolored text on each chunk, producing a rapid plain → colored → plain flash. The gate existed to avoid showing stale text/height, but it threw away all coloring to do so.Implementation
Replaced the exact-match gate with a streaming-aware per-line resolver,
resolveCodeBlockLines, inMarkdownComponents.tsx:CodeBlocknow decides highlight-vs-plain per line. Height is always driven by the currentplainLines, so there's no height jump. TheSECURITY AUDITinvariant is preserved:dangerouslySetInnerHTMLis only used for trusted Shiki HTML, plain text goes through a<code>child.HighlightedCode.tsx(tool result panes) is intentionally left unchanged — those panes replace content in-place rather than streaming appends, so the prefix assumption does not apply there.Validation
make static-check,make typecheck,make lint, andbun test src/browser/features/Messages/MarkdownComponents.test.tsx(17 pass / 0 fail) all green.Risks
Low and scoped to the streaming code-block render path. Worst case for a logic slip is a transient stale/plain line that self-corrects on the next highlight (the same failure mode the old gate guarded against). No change to highlighting output, security boundary, or non-streaming/settled rendering.
Generated with
mux• Model:anthropic:claude-opus-4-8• Thinking:xhigh• Cost:$3.28