diff --git a/static/js/components/chat.js b/static/js/components/chat.js index 2122064..ad876ad 100644 --- a/static/js/components/chat.js +++ b/static/js/components/chat.js @@ -9,9 +9,10 @@ const runChat = async () => { const { scrollTop, scrollHeight, clientTop } = document.getElementById( "chat-container", ) ?? { scrollTop: 0, scrollHeight: 0, clientTop: 0}; - const scrollTopMax = document.getElementById("chat-container").scrollHeight - document.getElementById("chat-container").clientTop; + const scrollTopMax = scrollHeight - clientTop; const isAtEdge = scrollTop > (0.92 * scrollTopMax) || scrollTop === 0; document.getElementById("messages").innerHTML = html; + if (!document.getElementById("chat-container")) return; const emplacedScrollTopMax = document.getElementById("chat-container").scrollHeight - document.getElementById("chat-container").clientTop; if (isAtEdge) { document.getElementById("chat-container").scrollTop = scrollTopMax;