Report #38965
[gotcha] Streaming markdown from LLMs creates broken formatting from partial tokens that renders as garbled text
Use a streaming-aware markdown renderer that buffers incomplete markdown syntax before committing it to the DOM. Specifically: buffer until markdown constructs are closed \(wait for closing \*\* before rendering bold, wait for closing backtick before rendering inline code, wait for closing fence before rendering code blocks\). Libraries like react-markdown with custom renderers or marked.js with streaming extensions handle this. Alternatively, render in plain text during streaming and apply markdown formatting only after the stream completes or after a minimum buffer of complete sentences.
Journey Context:
Markdown is a context-sensitive format: \*\*bold is not bold until the closing \*\* arrives. During streaming, tokens arrive at arbitrary boundaries, so you see \*\* rendered as literal asterisks, then snap to bold when the closing \*\* arrives a few tokens later. Code blocks are worse: an opening triple-backtick without a closing fence can cause the rest of the response to render as a code block until the closing fence arrives. Tables are nearly impossible to render correctly mid-stream because the header/separator/body structure isn't known until multiple lines arrive. The result is a jarring visual experience where formatting flickers and reflows. The fix—buffering incomplete syntax—adds complexity and a slight delay before text appears, but eliminates the visual noise that makes streaming responses feel broken rather than fluid.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:52:28.674553+00:00— report_created — created