You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
🐛 Bug: Scroll to bottom button not appearing and user message shifts after streaming finishes in "pin to send" autoscroll mode #5355
To reproduce, chat with the agent in pin to send autoscroll mode. We see that the scroll to bottom button does not appear and that the user messages shifts abruptly after the agent finishes streaming.
Reproduction with CPK chat with overriden slots:
Screen.Recording.2026-06-10.at.11.07.12.AM.mov
Reproduction with base CPK chat:
Screen.Recording.2026-06-10.at.11.05.30.AM.mov
✅ Expected Behavior
Scroll to bottom button should be present in pin to send mode and chat message should remain in the same position after streaming
Root cause analysis
For bottom scroll button not appearing, I believe the reason is that the useEffect in ScrollView that attaches scroll listeners has [scrollRef, mode] as dependencies. scrollRef is a stable useRef object, so the effect only runs on the initial render when scrollRef.current is still null (because the hasMounted guard renders a placeholder on the first pass, before the ref callback div mounts). The effect early-returns and never re-runs, leaving showScrollButton permanently false. (
The issues you've identified are indeed caused by a lack of reactive dependencies in the scroll-monitoring logic and a specific interaction between the "shrink-only" spacer and layout changes that occur when an agent finishes streaming (like suggestions appearing or the input container resizing).
The root cause for the button's absence in pin-to-send (and none) mode is that the useEffect responsible for attaching scroll listeners depends on the stable scrollRef object rather than the element itself.
Details
The issues you've identified are indeed caused by a lack of reactive dependencies in the scroll-monitoring logic and a specific interaction between the "shrink-only" spacer and layout changes that occur when an agent finishes streaming (like suggestions appearing or the input container resizing).
1. Scroll to Bottom Button Not Appearing
The root cause for the button's absence in pin-to-send (and none) mode is that the useEffect responsible for attaching scroll listeners depends on the stable scrollRef object rather than the element itself. Since the chat renders a placeholder until mounting, scrollRef.current is null on the first run and the effect never re-synchronizes.
Solution:
Update the useEffect dependencies in packages/react-core/src/v2/components/chat/CopilotChatView.tsx to use the state-tracked nonAutoScrollEl instead of the raw ref.
// packages/react-core/src/v2/components/chat/CopilotChatView.tsx// Change the dependency from [scrollRef, mode] to [nonAutoScrollEl, mode]useEffect(()=>{if(mode==="pin-to-bottom")return;constscrollElement=nonAutoScrollEl;// Use the state variableif(!scrollElement)return;constcheckScroll=()=>{constatBottom=scrollElement.scrollHeight-scrollElement.scrollTop-scrollElement.clientHeight<10;setShowScrollButton(!atBottom);};checkScroll();scrollElement.addEventListener("scroll",checkScroll);constresizeObserver=newResizeObserver(checkScroll);resizeObserver.observe(scrollElement);return()=>{scrollElement.removeEventListener("scroll",checkScroll);resizeObserver.disconnect();};},[nonAutoScrollEl,mode]);// Now correctly re-runs when the element mounts
2. User Message Shifting After Streaming
The "shift" occurs because when isRunning flips to false, several layout changes happen simultaneously:
The inputContainerHeight often changes (e.g., transition from "Stop" button to the full Input).
The hasSuggestions flag becomes true, which adds the suggestions component and reduces the paddingBottom of the scroll content (from 32px to 4px).
The usePinToSend hook's ResizeObserver is "shrink-only." When height is added (suggestions), it shrinks the spacer to compensate. However, if height is removed (the 28px padding reduction), the "shrink-only" guard prevents the spacer from growing to compensate. This discrepancy causes a jump in the total scrollable height, yanking the pinned message.
Solution:
The usePinToSend logic should allow the spacer to grow if the content height decreases, as long as the total "available space" remains consistent with the initial anchoring.
Modification to use-pin-to-send.ts:
// packages/react-core/src/v2/hooks/use-pin-to-send.tsconstro=newResizeObserver(()=>{if(!contentEl||!spacerEl||!scrollEl)return;constcontentHeight=contentEl.getBoundingClientRect().height;consttargetOffsetWithinContent=computeOffsetTop(targetEl,contentEl);constconsumedBelow=contentHeight-targetOffsetWithinContent-userMessageHeight;// instead of if (remaining < currentSpacerHeightRef.current)// allow the spacer to adjust in both directions to maintain the pinconstremaining=Math.max(0,spacerHeight-consumedBelow);spacerEl.style.height=`${remaining}px`;currentSpacerHeightRef.current=remaining;});
Summary of Fixes
Reactive Scroll Listeners: Ensure ScrollView re-attaches listeners once the DOM element is actually available by depending on element state.
Bi-directional Spacer Adjustment: Allow the pin-to-send spacer to grow or shrink in response to internal content height changes (like padding adjustments) to maintain the visual anchor point.
Confidence Assessment: High. The user's analysis of the scrollRef dependency is correct, and the "flash" behavior perfectly matches a layout conflict where paddingBottom is removed but the spacer is blocked from growing to fill the gap.
Activity
copilotkit-support-bot commentedon Jun 10, 2026
The issues you've identified are indeed caused by a lack of reactive dependencies in the scroll-monitoring logic and a specific interaction between the "shrink-only" spacer and layout changes that occur when an agent finishes streaming (like suggestions appearing or the input container resizing).
The root cause for the button's absence in
pin-to-send(andnone) mode is that theuseEffectresponsible for attaching scroll listeners depends on the stablescrollRefobject rather than the element itself.Details
The issues you've identified are indeed caused by a lack of reactive dependencies in the scroll-monitoring logic and a specific interaction between the "shrink-only" spacer and layout changes that occur when an agent finishes streaming (like suggestions appearing or the input container resizing).
1. Scroll to Bottom Button Not Appearing
The root cause for the button's absence in
pin-to-send(andnone) mode is that theuseEffectresponsible for attaching scroll listeners depends on the stablescrollRefobject rather than the element itself. Since the chat renders a placeholder until mounting,scrollRef.currentis null on the first run and the effect never re-synchronizes.Solution:
Update the
useEffectdependencies inpackages/react-core/src/v2/components/chat/CopilotChatView.tsxto use the state-trackednonAutoScrollElinstead of the raw ref.2. User Message Shifting After Streaming
The "shift" occurs because when
isRunningflips tofalse, several layout changes happen simultaneously:inputContainerHeightoften changes (e.g., transition from "Stop" button to the full Input).hasSuggestionsflag becomes true, which adds the suggestions component and reduces thepaddingBottomof the scroll content (from32pxto4px).The
usePinToSendhook'sResizeObserveris "shrink-only." When height is added (suggestions), it shrinks the spacer to compensate. However, if height is removed (the 28px padding reduction), the "shrink-only" guard prevents the spacer from growing to compensate. This discrepancy causes a jump in the total scrollable height, yanking the pinned message.Solution:
The
usePinToSendlogic should allow the spacer to grow if the content height decreases, as long as the total "available space" remains consistent with the initial anchoring.Modification to
use-pin-to-send.ts:Summary of Fixes
ScrollViewre-attaches listeners once the DOM element is actually available by depending on element state.pin-to-sendspacer to grow or shrink in response to internal content height changes (like padding adjustments) to maintain the visual anchor point.Confidence Assessment: High. The user's analysis of the
scrollRefdependency is correct, and the "flash" behavior perfectly matches a layout conflict wherepaddingBottomis removed but the spacer is blocked from growing to fill the gap.Documentation References:
Was this helpful?
If this solution worked for you, please click on the appropriate option below to help us improve:
✅ This was helpful | ❌ Need more help
Vishal0203 commentedon Jun 10, 2026
Tagging Nathan for visibility on this - @NathanTarbert
fix(react-core): stabilize pin-to-send scrolling (#5386)
tylerslaton commentedon Jun 12, 2026
Thanks to @westkite1201 for the fix 😄
fix(vue): adjust pin-to-send spacer in both directions to keep the us…
fix(vue): adjust pin-to-send spacer in both directions to keep the us…