Skip to content

Commit 002e81b

Browse files
Fixed chat error
1 parent 9a2a3ff commit 002e81b

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/chat/components/Chat/Chat.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,22 @@ const Chat = () => {
6363
const scrollToLastMessage = useCallback(async () => {
6464
const lastElement = chatMessagesRef.current
6565
?.lastChild as HTMLDivElement;
66-
lastElement.scrollIntoView({
67-
behavior: "smooth",
68-
block: "end",
69-
});
7066

71-
if (!lastElement.classList.contains("notification-showed")) {
72-
const userName = lastElement.childNodes[0]?.textContent?.trim();
73-
const message = lastElement.childNodes[1]?.textContent?.trim();
67+
if (lastElement) {
68+
lastElement.scrollIntoView({
69+
behavior: "smooth",
70+
block: "end",
71+
});
7472

75-
if (userName && message) {
76-
await notify(userName, message);
73+
if (!lastElement.classList.contains("notification-showed")) {
74+
const userName = lastElement.childNodes[0]?.textContent?.trim();
75+
const message = lastElement.childNodes[1]?.textContent?.trim();
7776

78-
lastElement.classList.add("notification-showed");
77+
if (userName && message) {
78+
await notify(userName, message);
79+
80+
lastElement.classList.add("notification-showed");
81+
}
7982
}
8083
}
8184
}, [notify]);

0 commit comments

Comments
 (0)