Skip to content
This repository was archived by the owner on Jan 29, 2026. It is now read-only.

Commit e1e3f44

Browse files
committed
feat: initFlag에 따라 최초 스크롤 진행
1 parent dcfa779 commit e1e3f44

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/tds-widget/src/chat/chat/chat-room-messages/use-chat-room-messages.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useRef } from 'react'
1+
import { useCallback, useEffect, useRef, useState } from 'react'
22
import DOMPurify from 'dompurify'
33

44
import {
@@ -57,6 +57,8 @@ export function useChatMessages<T = UserType>(
5757
const firstRenderForPrevScrollRef = useRef(true)
5858
const isWelcomeMessagePendingRef = useRef(false)
5959

60+
const [initComplete, setInitComplete] = useState(false)
61+
6062
const {
6163
messages,
6264
pendingMessages,
@@ -82,10 +84,17 @@ export function useChatMessages<T = UserType>(
8284
isWelcomeMessagePendingRef.current = true
8385
}
8486

85-
setScrollY(0)
87+
setInitComplete(true)
8688
})()
8789
}, []) // eslint-disable-line react-hooks/exhaustive-deps
8890

91+
useEffect(() => {
92+
if (initComplete) {
93+
setScrollY(0)
94+
}
95+
// eslint-disable-next-line react-hooks/exhaustive-deps
96+
}, [initComplete])
97+
8998
async function handleSendMessageAction({
9099
roomId,
91100
payload,

0 commit comments

Comments
 (0)