fix: smooth streaming markdown rendering#1187
fix: smooth streaming markdown rendering#1187jamesx0416 wants to merge 1 commit intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| const openingMatch = line.match(FENCE_OPEN_PATTERN); | ||
| if (openingMatch) { |
There was a problem hiding this comment.
🟡 Medium src/streaming-markdown.ts:206
When an unclosed inline code span is followed by a fence-like pattern on the next line (e.g., `some code\n```python), the function incorrectly enters fence mode and resets inlineState, losing track of the unclosed inline code delimiter. The original backtick remains unclosed in the output, causing incorrect markdown rendering. Consider checking inlineState.inlineCodeDelimiter == null before processing fence open patterns.
const openingMatch = line.match(FENCE_OPEN_PATTERN);
- if (openingMatch) {
+ if (openingMatch && inlineState.inlineCodeDelimiter == null) {🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/web/src/streaming-markdown.ts around lines 206-207:
When an unclosed inline code span is followed by a fence-like pattern on the next line (e.g., `` `some code\n[code fence]python ``), the function incorrectly enters fence mode and resets `inlineState`, losing track of the unclosed inline code delimiter. The original backtick remains unclosed in the output, causing incorrect markdown rendering. Consider checking `inlineState.inlineCodeDelimiter == null` before processing fence open patterns.
Evidence trail:
apps/web/src/streaming-markdown.ts lines 205-217 (REVIEWED_COMMIT): Fence open pattern handling that resets `inlineState` without checking if there's an unclosed inline code delimiter. Lines 229-231: Suffix generation that relies on `inlineState.inlineCodeDelimiter` to add closing backticks - but this value is null after the reset.
There was a problem hiding this comment.
@macroscopeapp fix it for me
What Changed
apps/web/src/streaming-markdown.tsapps/web/src/components/ChatMarkdown.tsxWhy
Streaming assistant output is often syntactically incomplete mid-token, which causes
react-markdownto show raw markdown markers like**, backticks,[](),~~, or<...>until the response finishes. This change temporarily appends closing delimiters for a narrow set of supported constructs during streaming so partial responses render more cleanly without changing the final stored message.The helper is intentionally scoped as a streaming UX repair layer rather than a full markdown parser.
UI Changes
This only affects in-flight assistant message rendering. There are no durable layout changes, and I did not capture before/after screenshots or video for this interaction polish.
Checklist
Note
Fix streaming markdown rendering by closing incomplete markdown constructs
finalizeStreamingMarkdowninstreaming-markdown.tsthat scans in-progress text and appends closing delimiters for unclosed fenced code blocks, inline code spans, link destinations, autolinks, and emphasis markers.ChatMarkdownappliesfinalizeStreamingMarkdownviauseMemowhenisStreamingis true, so React Markdown always receives syntactically balanced input.streaming-markdown.test.tscovers bold, inline code, fenced blocks, nested emphasis, nested parentheses in links, strikethrough, autolinks, and intraword underscores.📊 Macroscope summarized 4ce9181. 3 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues