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.
This commit is contained in:
2 files changed
+6
-4
No files matched your search
@@ -37,10 +37,10 @@
|
|||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
pinnedMessages = [...(pinnedMessages ?? []), ...res];
|
pinnedMessages = [...(pinnedMessages ?? []), ...res];
|
||||||
}
|
|
||||||
|
|
||||||
if (res.length === 0) {
|
if (res.length === 0) {
|
||||||
allItemsLoaded = true;
|
allItemsLoaded = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching pinned messages:', error);
|
console.error('Error fetching pinned messages:', error);
|
||||||
|
|||||||
@@ -35,7 +35,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const scrollToBottom = () => {
|
const scrollToBottom = () => {
|
||||||
messagesContainerElement.scrollTop = messagesContainerElement.scrollHeight;
|
if (messagesContainerElement) {
|
||||||
|
messagesContainerElement.scrollTop = messagesContainerElement.scrollHeight;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const initHandler = async () => {
|
const initHandler = async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user