Spaces:
Sleeping
Sleeping
fix auto scroll
Browse files- web/src/App.tsx +11 -2
web/src/App.tsx
CHANGED
|
@@ -270,8 +270,17 @@ function App() {
|
|
| 270 |
}, [token]);
|
| 271 |
|
| 272 |
useEffect(() => {
|
| 273 |
-
//
|
| 274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
}, [messages]);
|
| 276 |
|
| 277 |
const handleSendMessage = async () => {
|
|
|
|
| 270 |
}, [token]);
|
| 271 |
|
| 272 |
useEffect(() => {
|
| 273 |
+
// Only auto-scroll if user is near bottom (within 100px)
|
| 274 |
+
const container = messagesContainerRef.current;
|
| 275 |
+
if (container) {
|
| 276 |
+
const isNearBottom = container.scrollHeight - container.scrollTop - container.clientHeight < 100;
|
| 277 |
+
if (isNearBottom) {
|
| 278 |
+
// Use requestAnimationFrame to avoid scroll conflicts
|
| 279 |
+
requestAnimationFrame(() => {
|
| 280 |
+
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth', block: 'end' });
|
| 281 |
+
});
|
| 282 |
+
}
|
| 283 |
+
}
|
| 284 |
}, [messages]);
|
| 285 |
|
| 286 |
const handleSendMessage = async () => {
|