From 41bdb04b72304380371b19e12366ebe8d294fe0b Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Fri, 2 Oct 2026 19:57:48 -0400 Subject: [PATCH] make chat follow new messages when scrolled to bottom Fixes #106 --- lib/helpers/hooks/chat_scroll.dart | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/helpers/hooks/chat_scroll.dart b/lib/helpers/hooks/chat_scroll.dart index 877264e..7845576 100644 --- a/lib/helpers/hooks/chat_scroll.dart +++ b/lib/helpers/hooks/chat_scroll.dart @@ -94,6 +94,27 @@ final class ChatScroll({ ); }, [controllerData, anchorId.value]); + final lastRowId = split.live.lastOrNull; + final previousLastRowId = useRef(null); + + useEffect(() { + final previous = previousLastRowId.value; + previousLastRowId.value = lastRowId; + + if (previous == null || lastRowId == null || previous == lastRowId) { + return null; + } + if (!atBottom.value || contextualEvent.value != null) return null; + + WidgetsBinding.instance.addPostFrameCallback((_) { + if (!scrollController.hasClients) return; + + scrollController.jumpTo(scrollController.position.minScrollExtent); + }); + + return null; + }, [lastRowId]); + useEffect( () { const loadThreshold = 500.0;