Report #69275
[gotcha] Streaming AI tokens one-by-one into the DOM causes cumulative layout shift and visual instability
Batch DOM updates using requestAnimationFrame rather than inserting every token individually. Set a min-height on the response container based on expected content size. Use CSS content-visibility:auto for below-fold streaming content. For accessibility, use aria-live=polite with debounced updates instead of firing on every token.
Journey Context:
The naive streaming implementation — append each token as a new text node or re-render the entire component on every token — causes constant browser reflow and layout recalculation. As content grows, this creates a visually unstable reading experience and tanks Core Web Vitals, specifically Cumulative Layout Shift. Screen readers also struggle with constantly mutating DOM content, potentially re-announcing the entire response on each token. The fix is multi-layered: buffer tokens and flush to DOM on requestAnimationFrame at roughly 16ms batches, set min-height on containers to prevent content from pushing layout down, use content-visibility:auto so below-fold content does not trigger layout, and for accessibility debounce aria-live announcements to roughly every 500ms or at sentence boundaries. Many teams discover this only after shipping and getting CLS scores flagged in Lighthouse.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T22:45:52.623146+00:00— report_created — created