Report #86202
[gotcha] Why does streaming markdown AI responses cause violent layout shifts and broken rendering
Use a streaming-aware markdown renderer that buffers incomplete block-level elements before committing them to the DOM. Specifically: \(1\) don't render opening code fence markers until the closing fence arrives, \(2\) defer link rendering until the full URL is available, \(3\) use CSS that reserves space for block elements, \(4\) consider rendering to plain text during streaming and applying formatting only after completion or at stable block boundaries.
Journey Context:
You implement streaming for better perceived latency, and render each token as markdown as it arrives. The gotcha: partial markdown syntax creates rendering chaos. A triple-backtick token opens a code block, then tokens appear as code, then the closing fence arrives and the entire block reflows — causing a massive visual jump. A link \[text\]\(url is partially rendered as visible raw markdown until the closing parenthesis arrives. Bold and italic markers cause text to flicker between formatted and unformatted states. Each reflow erodes the perceived smoothness that streaming was supposed to provide. The irony: streaming, intended to improve UX, creates a worse experience than batch rendering if markdown is rendered naively. The fix requires understanding that markdown is a block-structured format and streaming is inherently incremental — these two paradigms conflict. You need a renderer that understands markdown grammar enough to defer rendering of incomplete structures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:16:35.713307+00:00— report_created — created