From 743b59b69857da81b214970ec9252bc918ad243d Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Thu, 20 Feb 2025 22:22:57 -0500 Subject: Only check for message visibility while a channel is actually attached to the DOM. Prevents this from breaking during DOM unmounting, when leaving a channel. --- ui/routes/(app)/ch/[channel]/+page.svelte | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'ui/routes') diff --git a/ui/routes/(app)/ch/[channel]/+page.svelte b/ui/routes/(app)/ch/[channel]/+page.svelte index 7bd0e10..25bc318 100644 --- a/ui/routes/(app)/ch/[channel]/+page.svelte +++ b/ui/routes/(app)/ch/[channel]/+page.svelte @@ -22,14 +22,15 @@ } function getLastVisibleMessage() { - const parentElement = activeChannel; - const childElements = parentElement.getElementsByClassName('message'); - const lastInView = Array.from(childElements) - .reverse() - .find((el) => { - return inView(parentElement, el); - }); - return lastInView; + if (activeChannel) { + const childElements = activeChannel.getElementsByClassName('message'); + const lastInView = Array.from(childElements) + .reverse() + .find((el) => { + return inView(activeChannel, el); + }); + return lastInView; + } } function setLastRead() { -- cgit v1.2.3