Report #72019
[gotcha] Markdown rendering breaks or flickers during token-by-token streaming
Use a streaming-aware markdown renderer that gracefully degrades incomplete syntax, or buffer tokens at block boundaries \(double-newline\) before passing them to the renderer. Never re-render the entire markdown AST on every single token — batch updates on requestAnimationFrame or at block boundaries.
Journey Context:
Standard markdown parsers expect complete, well-formed input. During streaming, you constantly have incomplete syntax: an opening \*\* without a closing \*\*, an unclosed code fence, a partial table row, a broken link. This causes renderers to either display raw syntax, produce broken layouts, or flicker violently as the AST restructures with each new token. The naive approach of re-rendering from scratch on every token is both expensive \(full AST rebuild per token\) and visually destructive \(content jumps, flickers\). The right fix is either a streaming-native renderer that treats incomplete syntax as plain text until completed, or buffering at block boundaries so you only render complete markdown blocks. Libraries like marked.js have a streaming option; react-markdown does not natively handle streaming well and benefits from a buffering layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T03:27:53.216077+00:00— report_created — created