Spaces:
Running
Running
fix: chat scroll – use bottomRef sentinel + scrollIntoView instead of broken scrollRef on ScrollArea wrapper
Browse files
frontend/src/components/chat/ChatPanel.tsx
CHANGED
|
@@ -35,14 +35,12 @@ export default function ChatPanel({ activeDoc, onCitationClick }: Props) {
|
|
| 35 |
const [messages, setMessages] = useState<ChatMsg[]>([]);
|
| 36 |
const [input, setInput] = useState("");
|
| 37 |
const [streaming, setStreaming] = useState(false);
|
| 38 |
-
const
|
| 39 |
const prevDocId = useRef<string | null>(null);
|
| 40 |
|
| 41 |
-
// Auto-scroll to bottom
|
| 42 |
useEffect(() => {
|
| 43 |
-
|
| 44 |
-
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
| 45 |
-
}
|
| 46 |
}, [messages]);
|
| 47 |
|
| 48 |
// Load history on doc change
|
|
@@ -170,7 +168,7 @@ export default function ChatPanel({ activeDoc, onCitationClick }: Props) {
|
|
| 170 |
return (
|
| 171 |
<div className="h-full flex flex-col">
|
| 172 |
{/* ── Chat Messages ──────────────────────────── */}
|
| 173 |
-
<ScrollArea className="flex-1 px-4"
|
| 174 |
{messages.length === 0 ? (
|
| 175 |
<div className="h-full flex flex-col items-center justify-center py-20">
|
| 176 |
<div className="w-16 h-16 rounded-2xl bg-primary/10 flex items-center justify-center mb-4">
|
|
@@ -199,6 +197,8 @@ export default function ChatPanel({ activeDoc, onCitationClick }: Props) {
|
|
| 199 |
))}
|
| 200 |
</div>
|
| 201 |
)}
|
|
|
|
|
|
|
| 202 |
</ScrollArea>
|
| 203 |
|
| 204 |
{/* ── Input Area ─────────────────────────────── */}
|
|
|
|
| 35 |
const [messages, setMessages] = useState<ChatMsg[]>([]);
|
| 36 |
const [input, setInput] = useState("");
|
| 37 |
const [streaming, setStreaming] = useState(false);
|
| 38 |
+
const bottomRef = useRef<HTMLDivElement>(null);
|
| 39 |
const prevDocId = useRef<string | null>(null);
|
| 40 |
|
| 41 |
+
// Auto-scroll to bottom whenever messages change
|
| 42 |
useEffect(() => {
|
| 43 |
+
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
|
|
|
|
|
| 44 |
}, [messages]);
|
| 45 |
|
| 46 |
// Load history on doc change
|
|
|
|
| 168 |
return (
|
| 169 |
<div className="h-full flex flex-col">
|
| 170 |
{/* ── Chat Messages ──────────────────────────── */}
|
| 171 |
+
<ScrollArea className="flex-1 px-4">
|
| 172 |
{messages.length === 0 ? (
|
| 173 |
<div className="h-full flex flex-col items-center justify-center py-20">
|
| 174 |
<div className="w-16 h-16 rounded-2xl bg-primary/10 flex items-center justify-center mb-4">
|
|
|
|
| 197 |
))}
|
| 198 |
</div>
|
| 199 |
)}
|
| 200 |
+
{/* Sentinel element – scrolled into view on new messages */}
|
| 201 |
+
<div ref={bottomRef} />
|
| 202 |
</ScrollArea>
|
| 203 |
|
| 204 |
{/* ── Input Area ─────────────────────────────── */}
|