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

Commit cfed30a

Browse files
committed
fix: useIsomorphicLayoutEffect 적용
1 parent 0cc0162 commit cfed30a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

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

44
import {
@@ -32,6 +32,9 @@ interface ChatMessagesProps<T = UserType> {
3232
createRoom?: () => Promise<ChatRoomDetailInterface | undefined>
3333
}
3434

35+
const useIsomorphicLayoutEffect =
36+
typeof window !== 'undefined' ? useLayoutEffect : useEffect
37+
3538
export function useChatMessages<T = UserType>(
3639
{
3740
scrollToBottomOnNewMessage = true,
@@ -68,7 +71,7 @@ export function useChatMessages<T = UserType>(
6871
} = useChatMessagesContext<T>()
6972
const api = useChatApiService<T>()
7073

71-
useEffect(() => {
74+
useIsomorphicLayoutEffect(() => {
7275
;(async function () {
7376
await initMessages()
7477

@@ -82,9 +85,7 @@ export function useChatMessages<T = UserType>(
8285
isWelcomeMessagePendingRef.current = true
8386
}
8487

85-
setTimeout(() => {
86-
setScrollY(0)
87-
}, 0)
88+
setScrollY(0)
8889
})()
8990
}, []) // eslint-disable-line react-hooks/exhaustive-deps
9091

0 commit comments

Comments
 (0)