From 5112e0b62c2098836a92cf41ce7119512d243d31 Mon Sep 17 00:00:00 2001 From: G30 <50341825+silentoplayz@users.noreply.github.com> Date: Sun, 31 May 2026 18:01:17 -0400 Subject: [PATCH] fix: add null guards to channel Thread and PinnedMessagesModal components (#25209) Thread.svelte: Add null check for messagesContainerElement in scrollToBottom() to match the existing pattern in Channel.svelte. Prevents potential TypeError when the DOM element is not yet bound during rapid thread switches. PinnedMessagesModal.svelte: Move res.length check inside the if (res) block. Previously, res.length was accessed unconditionally after a guarded block, causing TypeError when the API call fails and the .catch() returns null. --- src/lib/components/channel/PinnedMessagesModal.svelte | 6 +++--- src/lib/components/channel/Thread.svelte | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/components/channel/PinnedMessagesModal.svelte b/src/lib/components/channel/PinnedMessagesModal.svelte index 2d24671d6a..3e6832e005 100644 --- a/src/lib/components/channel/PinnedMessagesModal.svelte +++ b/src/lib/components/channel/PinnedMessagesModal.svelte @@ -37,10 +37,10 @@ if (res) { pinnedMessages = [...(pinnedMessages ?? []), ...res]; - } - if (res.length === 0) { - allItemsLoaded = true; + if (res.length === 0) { + allItemsLoaded = true; + } } } catch (error) { console.error('Error fetching pinned messages:', error); diff --git a/src/lib/components/channel/Thread.svelte b/src/lib/components/channel/Thread.svelte index 5049337312..ba03f3a69f 100644 --- a/src/lib/components/channel/Thread.svelte +++ b/src/lib/components/channel/Thread.svelte @@ -35,7 +35,9 @@ } const scrollToBottom = () => { - messagesContainerElement.scrollTop = messagesContainerElement.scrollHeight; + if (messagesContainerElement) { + messagesContainerElement.scrollTop = messagesContainerElement.scrollHeight; + } }; const initHandler = async () => {