Report #48742
[gotcha] Streaming markdown responses cause jarring cumulative layout shift
Use a streaming-aware markdown renderer that buffers until structural elements are unambiguous. Specifically: \(1\) do not commit to a heading render until the full heading text and newline arrive, \(2\) do not open a code block render until the language identifier and closing backticks are present or use a placeholder container, \(3\) apply CSS with fixed sizing for headings and pre-allocated containers for code blocks to minimize reflow. For code blocks, buffer until the closing triple backticks arrive before rendering.
Journey Context:
When markdown streams token-by-token, the DOM structure changes radically with each token. A line starting with '\#' might become a heading or just be a literal hash. Triple backticks open a code block but the language identifier and closing backticks have not arrived. Naive per-token re-rendering causes: headings that appear then vanish, code blocks that flash open then close, list items that renumber, and tables that reshape. This creates severe Cumulative Layout Shift. The fix is structural buffering — waiting until enough tokens arrive to commit to a DOM structure. The tradeoff: buffering adds a small delay before content appears, but eliminates the jittery experience that makes streaming AI responses feel broken and untrustworthy.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:18:01.429343+00:00— report_created — created