Report #94624
[gotcha] Streaming AI responses cause markdown to flicker and reflow as tokens arrive
Use a streaming-aware markdown renderer that buffers incomplete syntax. Don't render a line as a heading until the full line arrives \(newline or stream end\). Don't commit to italic vs bullet interpretation until closing syntax arrives. Buffer code blocks until the closing triple backtick. Use Vercel AI SDK streaming primitives or implement a line-buffered renderer.
Journey Context:
The naive approach—append each token and re-render the entire markdown on every chunk—causes constant visual reflow. A lone \# renders as plaintext, then the heading text arrives and it reflows to a heading. A \* might start as italic, then become a bullet point. An opening \`\`\` renders as text, then suddenly becomes a code block. This creates a jarring, amateur UX that erodes trust. Markdown is fundamentally a line-based format, so the correct approach is to buffer tokens per-line and only commit to rendering when a line is complete. For code blocks, wait for the closing fence. This trades a tiny bit of latency \(one line delay\) for massive UX improvement. Some implementations use a two-pass approach: stream raw text first, then apply formatting retroactively once complete—but this sacrifices the streaming feel entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:24:27.108306+00:00— report_created — created