Skip to content

feat(platform): streaming markdown line buffer and split rendering#903

Merged
larryro merged 3 commits into
mainfrom
feat/chat-streaming-line-buffer
Mar 28, 2026
Merged

feat(platform): streaming markdown line buffer and split rendering#903
larryro merged 3 commits into
mainfrom
feat/chat-streaming-line-buffer

Conversation

@larryro

@larryro larryro commented Mar 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add a line-buffer utility that cleanly handles stream chunk buffering, ensuring markdown is only emitted at complete line boundaries
  • Split streaming markdown into stable (already-completed blocks) and streaming (in-progress block) portions — stable blocks are parsed once and memoized, reducing per-frame rendering work from O(full_text) to O(last_block)
  • Improve remendMarkdown with tilde fence support, better trailing marker detection for underscores and CJK text, and a targetCPS=0 guard in useStreamBuffer

Test plan

  • Unit tests added for line-buffer, find-block-split, and updated remend-markdown tests
  • Unit tests updated for use-stream-buffer and incremental-markdown
  • Manually verify streaming chat messages render smoothly without flicker
  • Verify completed markdown blocks don't re-render during streaming
  • Verify code fences (backtick and tilde) render correctly mid-stream

Summary by CodeRabbit

  • New Features

    • Added smooth drain animation phase when text streaming completes, gradually revealing buffered content
    • Enhanced markdown streaming stability to prevent partial syntax flicker (code fences, emphasis markers)
  • Improvements

    • Improved accessibility with aria-busy attributes for animated elements
    • Refined cursor rendering to ensure single cursor display during streaming animation
    • Better handling of special markdown constructs (code blocks, thematic breaks, emphasis) during character-by-character reveal

larryro added 2 commits March 28, 2026 10:15
Extract line-buffering logic into a dedicated utility for cleaner
stream chunk handling. Update incremental markdown to use a single
visible cursor via layout-effect deduplication. Simplify the stream
buffer hook and typewriter text component accordingly.
…ns for faster rendering

Introduce a block-level split point that separates already-completed markdown
blocks from the in-progress block during typewriter animation. Stable blocks
are parsed once and memoized via a new StableMarkdown component, reducing
per-frame work from O(full_text) to O(last_block). Also adds tilde fence
support to remendMarkdown, fixes trailing marker detection for underscores
and CJK text, and guards against targetCPS=0 in useStreamBuffer.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Knip flagged `unified` as an unlisted dependency. Derive the
PluggableList type from react-markdown's own Options instead.
@larryro larryro merged commit ca3eaf3 into main Mar 28, 2026
16 checks passed
@larryro larryro deleted the feat/chat-streaming-line-buffer branch March 28, 2026 04:04
@coderabbitai

coderabbitai Bot commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR refactors the streaming markdown reveal mechanism from anchor-based to block-based splitting. It removes the anchorPosition export from useStreamBuffer and replaces it with findBlockSplitPoint, which determines stable split boundaries using double-newline delimiters. New line-buffer utilities (isAmbiguousPartialLine, isAtTrailingEmptyMarker, findSyntaxSkipEnd) prevent partial syntax rendering during incremental reveals. The drain behavior on stream-end changes from immediate reveal to animated draining at 3× the character-reveal rate. IncrementalMarkdown now accepts aria-busy for accessibility and enforces a single-cursor guarantee via useLayoutEffect. remendMarkdown extends tilde fence support and relocates trailing whitespace before closing emphasis markers. Supporting test suites are refactored to focus on drain and line-buffer behaviors, and vite.config.ts adds explicit proxy routes for storage and action API endpoints.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(platform): streaming markdown line buffer and split rendering' clearly and concisely summarizes the main changes: introduction of streaming markdown line buffering and split rendering logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/chat-streaming-line-buffer

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

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