diff --git a/frontend/src/components/Messages.svelte b/frontend/src/components/Messages.svelte index 2149b0b..a7343b8 100644 --- a/frontend/src/components/Messages.svelte +++ b/frontend/src/components/Messages.svelte @@ -8,7 +8,6 @@ export let channelId; let scrollTarget; - let scrollAnchor; let shouldAutoscroll = true; let lastScrollHeight = null; let isScrolledToBottom = true; @@ -27,16 +26,16 @@ lastScrollHeight = null; return; } - if (shouldAutoscroll && scrollAnchor) { + if (shouldAutoscroll) { messagesLog("[afterUpdate] performing autoscroll..."); - scrollAnchor.scrollIntoView(false); + scrollTarget.scrollTo(0, scrollTarget.scrollHeight); } }); }); const onScroll = (e) => { - const { scrollHeight, scrollTop, clientHeight } = e.target; - if ((scrollHeight - scrollTop - clientHeight) <= 20) { // user scrolled to bottom + const { offsetHeight, scrollTop, scrollHeight } = e.target; + if ((offsetHeight + scrollTop) > (scrollHeight - 20)) { // user scrolled to bottom messages.setIsCollectingOldMessages(true); shouldAutoscroll = true; isScrolledToBottom = true; @@ -62,12 +61,11 @@ const windowDidResize = () => { // TODO: hack - // showSidebar is false on small viewports // scrolling to bottom when the virtual keyboard pops up does not work on chromium purely based on isScrolledToBottom for some reason if (isScrolledToBottom || $smallViewport) { messagesLog("[windowDidResize] window resized, queueing microtask to scroll to bottom..."); queueMicrotask(() => { - scrollAnchor.scrollIntoView(false); + scrollTarget.scrollTo(0, scrollTarget.scrollHeight); messagesLog("[windowDidResize] scroll to bottom microtask finished."); }); } @@ -123,5 +121,4 @@ {/if} {/each} -