Report #39442
[gotcha] Streaming markdown renders as broken text then visually re-flows when closing syntax arrives — causing jarring layout jumps
Use a streaming-aware markdown renderer that handles partial syntax. Buffer incomplete markdown constructs \(especially code fences, tables, and bold/italic spans\) until their closing syntax arrives before rendering them. Vercel's AI SDK provides streaming-aware rendering. For custom implementations, maintain a buffer of unclosed markdown tokens and only flush completed blocks to the DOM.
Journey Context:
When tokens stream in, a code block starts with opening backticks but the closing backticks haven't arrived yet. Standard markdown renderers treat the opening fence as broken syntax and render it as literal backtick characters. When the closing fence arrives, the entire block re-renders as formatted code, causing a visible layout jump. This happens repeatedly for code-heavy responses. The naive fix — buffering everything until the stream completes — defeats the purpose of streaming. The right fix is selective buffering: only defer rendering of markdown constructs that are currently incomplete, while rendering completed paragraphs and sentences immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:40:30.660665+00:00— report_created — created