How to stop chat autoscroll when AI message streams #730
Unanswered
james-pratama
asked this question in
Q&A
Replies: 1 comment 2 replies
-
@james-pratama you can controll it via one options is to disbale the scroll adjustment when receiving messages, or enable it only when scrolling backward, something like const rowVirtualizer = useVirtualizer({
count,
getScrollElement: () => parentRef.current,
estimateSize: () => 1000,
overscan: 5,
});
rowVirtualizer.shouldAdjustScrollPositionOnItemSizeChange = (item, _, instance) => {
return item.start < instance.scrollOffset && instance.scrollDirection === 'backward'
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am building an AI tool that has a chat feature. I am using Vercel's RSC SDK to stream messages, and showing those messages on the client from the array provided by useUIState. I feed UIState messages into Tanstack Virtual, and return message.component in each row, which is a StreamableValue.
https://sdk.vercel.ai/examples/next-app/state-management/ai-ui-states
Everything works fine, except when a new message is being streamed and it is visible on the screen, the list continuously autoscrolls to the bottom until the message stops streaming. Anytime a new message is streamed, it will autoscroll user to bottom unless the user is scrolled above past the current message being streamed.
Tried adding overflowAnchor: "none" but does not work. The autoscroll occurs even when I don't implement any scroll function of my own or use scrollToIndex, on both Safari and Chrome.
Is this a known issue that it autoscrolls when content is being streamed?
Scroll.mov
Beta Was this translation helpful? Give feedback.
All reactions