Skip to content

feat(chat): render streamed markdown progressively, token by token#41

Merged
albanm merged 5 commits into
mainfrom
feat-better-streamed-markdown
Jun 21, 2026
Merged

feat(chat): render streamed markdown progressively, token by token#41
albanm merged 5 commits into
mainfrom
feat-better-streamed-markdown

Conversation

@albanm

@albanm albanm commented Jun 21, 2026

Copy link
Copy Markdown
Member

Render streamed assistant markdown progressively, token by token, instead of popping in whole at blank-line block boundaries — list items appear one by one, prose appears line by line, and inline emphasis is closed optimistically while it streams.

Isolated to ui/src/utils/markdown.ts; the marked → sanitize → v-html pipeline is unchanged. renderStreamingMarkdown now feeds it a safe buffer from two pure helpers: streamingSafeBuffer (lexer-driven per-block-type rule) and repairInline (synthesizes closers for open `/*/_/~~). Mermaid fences and pre-delimiter tables are held back; real tables commit complete rows. Covered by 29 unit tests.

Why: long lists and paragraphs previously stayed hidden until their closing blank line, making streaming feel laggy and janky.

Heads-up: renderStreamingMarkdown is on the render path for every streamed message. The final (non-streaming) render short-circuits to the unchanged renderMarkdown, so committed messages are unaffected — only mid-stream frames use the new logic. Brief, self-correcting reflow of ambiguous inline markup mid-stream is an accepted, documented trade-off.

albanm and others added 5 commits June 21, 2026 19:06
…markdown

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…streamed markdown

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…Markdown

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Final-review hardening: marked collapses \r\n to \n internally, so token.raw
would be shorter than the source and activeStart would point at the wrong index
for CRLF input. Normalize at entry; output is unchanged for the usual LF case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@albanm albanm merged commit 2bcaec3 into main Jun 21, 2026
4 checks passed
@albanm albanm deleted the feat-better-streamed-markdown branch June 21, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant