fraudTech commited on
Commit
3c4153e
·
1 Parent(s): 35cd2f4

fix auto scroll

Browse files
Files changed (1) hide show
  1. web/src/App.tsx +11 -2
web/src/App.tsx CHANGED
@@ -270,8 +270,17 @@ function App() {
270
  }, [token]);
271
 
272
  useEffect(() => {
273
- // Always scroll to bottom when messages change
274
- messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
 
 
 
 
 
 
 
 
 
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 () => {