Repository navigation
Description
Problem Statement
When AI continuously outputs streaming content in the chat page (e.g., "write an article about environment with 1000 words"), the browser scrollbar position jumps and content moves up and down, creating a non-smooth user experience.
Current State
-
Layout height mismatch in streaming markdown: In
incremental-markdown.tsx, thestreaming-text-layout-reference(hidden layer) renders full content whilestreaming-text-reveal(visible layer) renders partial content. When markdown rendering produces different heights, the visible layer's height doesn't match, causing layout shifts. -
No continuous auto-scroll during streaming: Current implementation only scrolls ONCE when
isLoadingbecomes true, but as content grows during streaming, the scroll doesn't follow the new content. -
Scroll position conflicts: When content height changes, the browser adjusts scroll position, combined with no auto-scroll tracking, creating visible jumping.
Proposed Solution
- Fix layout stability: Ensure consistent height between layout reference and reveal layers by rendering full content in both layers and using CSS masking for reveal
- Implement continuous auto-scroll: Use ResizeObserver to detect content growth and scroll smoothly
- Add CSS
scrollbar-gutter: stable: Reserve space for scrollbar to prevent layout shifts - Respect user intent: If user scrolls up, disable auto-scroll; re-enable when scrolling to bottom
Affected Components
-
services/platform/app/(app)/dashboard/[id]/chat/components/incremental-markdown.tsx -
services/platform/app/(app)/globals.css -
services/platform/hooks/use-auto-scroll.ts(new) -
services/platform/app/(app)/dashboard/[id]/chat/components/chat-interface.tsx
Acceptance Criteria
- Content height stays stable during streaming (no jumping)
- Auto-scroll follows content during streaming
- User can scroll up without being pulled back down
- Scroll-to-bottom button re-enables auto-scroll
- No visible scrollbar jumping when content grows
- Performance: no jank during streaming
- Long articles (1000+ words) render smoothly
🤖 Generated with Claude Code
Activity
larryro commentedon Jan 5, 2026
Implementation Plan
Step 1: Fix Layout Stability in Streaming Markdown
File:
services/platform/app/(app)/dashboard/[id]/chat/components/incremental-markdown.tsxProblem: The
streaming-text-reveallayer usesposition: absolutebut its height differs fromstreaming-text-layout-referencebecause they render different content (partial vs full).Solution: Change the architecture to ensure height stability:
overflow: hiddenon container instead of absolute positioningclip-pathormaskto reveal content without changing layoutStep 2: Update CSS for Clip-Based Reveal
File:
services/platform/app/(app)/globals.cssStep 3: Create
use-auto-scroll.tsHookFile:
services/platform/hooks/use-auto-scroll.ts(NEW)Key features:
ResizeObserverrequestAnimationFramefor smooth scrollingStep 4: Update
chat-interface.tsxFile:
services/platform/app/(app)/dashboard/[id]/chat/components/chat-interface.tsxChanges:
useAutoScrollhookscrollbar-gutter-stableclass to scroll containerFiles to Modify
incremental-markdown.tsxglobals.cssuse-auto-scroll.tschat-interface.tsxPotential Risks
Testing Strategy
🤖 Generated with Claude Code
Israeltheminer commentedon Jan 5, 2026
Implementation Summary
Fixed the scroll jumping issue with a simpler approach than originally proposed.
Root Cause
Browser scroll anchoring was causing scroll position jumps when content height changed during streaming. The
streaming-text-layout-referencelayer grows as new text arrives, and the browser's scroll anchoring tries to "fix" the scroll position, causing visible jumps.Solution
1. Disabled browser scroll anchoring (
globals.css)2. Created
useAutoScrollhook (hooks/use-auto-scroll.ts)ResizeObserverto detect content growth3. Updated
chat-interface.tsxuseAutoScrollhook (replaceduseThrottledScroll)Why This Approach vs. Original Proposal
The issue proposed rendering full content in both layers with CSS
clip-pathmasking. A simpler approach was chosen:Both approaches solve the problem, but this one is simpler and avoids doubling the markdown rendering work.
PR: #92
fix(chat): smooth scrollbar behavior during AI streaming output (#86)