[RAPID-fix] 스크롤 근본 원인 수정: isOpen deps 추가로 메신저 열릴 때마다 하단 스크롤

This commit is contained in:
2026-03-31 16:23:05 +09:00
parent 0780410506
commit 6fdc4d8fb8

View File

@@ -16,7 +16,7 @@ interface ChatPanelProps {
export function ChatPanel({ room }: ChatPanelProps) {
const { user } = useAuth();
const { selectedRoomId } = useMessengerContext();
const { selectedRoomId, isOpen } = useMessengerContext();
const { data: messages } = useMessages(selectedRoomId);
const markAsRead = useMarkAsRead();
const updateRoom = useUpdateRoom();
@@ -38,14 +38,15 @@ export function ChatPanel({ room }: ChatPanelProps) {
// Scroll to bottom: sentinel scrollIntoView before paint (no visible jump)
useLayoutEffect(() => {
bottomRef.current?.scrollIntoView();
}, [selectedRoomId, lastMessageId]);
if (isOpen) bottomRef.current?.scrollIntoView();
}, [selectedRoomId, lastMessageId, isOpen]);
// Second pass for async image loads
useEffect(() => {
if (!isOpen) return;
const t = setTimeout(() => { bottomRef.current?.scrollIntoView(); }, 600);
return () => clearTimeout(t);
}, [lastMessageId, selectedRoomId]);
}, [lastMessageId, selectedRoomId, isOpen]);
// Re-attach scroll listener whenever room changes (scrollRef mounts after room is set)
useEffect(() => {