From 3481379732c4f3836f9383a7b44fc7ce3d0c0751 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Wed, 15 Mar 2023 10:08:08 -0500 Subject: [PATCH] fix: make auto scroll work with images --- src/components/ChatTranscript/ChatTranscript.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/ChatTranscript/ChatTranscript.tsx b/src/components/ChatTranscript/ChatTranscript.tsx index 38ab6bd..10587b7 100644 --- a/src/components/ChatTranscript/ChatTranscript.tsx +++ b/src/components/ChatTranscript/ChatTranscript.tsx @@ -30,8 +30,12 @@ export const ChatTranscript = ({ const lastChild = children[children.length - 1] const lastChildHeight = lastChild.clientHeight const previousScrollTopMax = scrollTopMax - lastChildHeight + + // Accounts for rounding errors in layout calculations + const marginBuffer = 1 + const wasPreviouslyScrolledToBottom = - Math.ceil(scrollTop) >= Math.ceil(previousScrollTopMax) + Math.ceil(scrollTop) >= Math.ceil(previousScrollTopMax) - marginBuffer const wasMessageLogPreviouslyEmpty = previousMessageLogLength === 0 const shouldScrollToLatestMessage = wasPreviouslyScrolledToBottom || wasMessageLogPreviouslyEmpty