Improve scroll handling and robustness for chat UI
All checks were successful
Build Frontend / build (push) Successful in 1m15s

Added 'overscroll-behavior: contain' to body and Chromebook scroll containers to prevent unwanted scroll chaining. Updated scrollToBottom utilities to handle null/undefined containers and errors gracefully. Fixed ChatDetail to use the correct scroll handler function.
This commit is contained in:
g
2026-01-14 06:06:03 +00:00
parent 5e8ba7bd0a
commit 5de8f80007
5 changed files with 36 additions and 16 deletions

View File

@@ -4,6 +4,7 @@
body { body {
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
overscroll-behavior: contain;
} }
@layer utilities { @layer utilities {

View File

@@ -347,7 +347,7 @@ export default function ChatDetail({ chatId }: { chatId: string }) {
// If near bottom, scroll to new messages // If near bottom, scroll to new messages
if (isNearBottom()) { if (isNearBottom()) {
setTimeout(scrollToBottom, 50); setTimeout(scrollToBottomHandler, 50);
} }
// Set timeout to mark new messages as read // Set timeout to mark new messages as read
@@ -447,7 +447,7 @@ export default function ChatDetail({ chatId }: { chatId: string }) {
setMessages(prev => [...prev, tempMessage]); setMessages(prev => [...prev, tempMessage]);
// Scroll to bottom to show the new message // Scroll to bottom to show the new message
setTimeout(scrollToBottom, 50); setTimeout(scrollToBottomHandler, 50);
try { try {
setSending(true); setSending(true);

View File

@@ -354,7 +354,7 @@ export default function ChatTable() {
<div> <div>
<div className="font-semibold text-sm flex items-center gap-2"> <div className="font-semibold text-sm flex items-center gap-2">
{chat.telegramUsername ? ( {chat.telegramUsername ? (
<span className="text-blue-400">@{chat.telegramUsername}</span> <span>@{chat.telegramUsername}</span>
) : ( ) : (
<span className="text-foreground">Customer {chat.buyerId.slice(0, 6)}...</span> <span className="text-foreground">Customer {chat.buyerId.slice(0, 6)}...</span>
)} )}

View File

@@ -11,6 +11,8 @@ export function useChromebookScroll() {
if (!container) return; if (!container) return;
// Enhanced scrolling for Chromebooks // Enhanced scrolling for Chromebooks
container.style.overscrollBehavior = 'contain';
const handleTouchStart = (e: TouchEvent) => { const handleTouchStart = (e: TouchEvent) => {
// Prevent default touch behavior that might interfere with scrolling // Prevent default touch behavior that might interfere with scrolling
if (e.touches.length === 1) { if (e.touches.length === 1) {
@@ -71,15 +73,32 @@ export function useChromebookScroll() {
* Hook for smooth scrolling to bottom (useful for chat interfaces) * Hook for smooth scrolling to bottom (useful for chat interfaces)
*/ */
export function useSmoothScrollToBottom() { export function useSmoothScrollToBottom() {
const scrollToBottom = (container: HTMLElement) => { const scrollToBottom = (container: HTMLElement | null | undefined) => {
container.scrollTo({ if (!container || typeof container !== 'object') return;
top: container.scrollHeight,
behavior: 'smooth' try {
}); if ('scrollTo' in container && typeof container.scrollTo === 'function') {
container.scrollTo({
top: container.scrollHeight,
behavior: 'smooth'
});
} else {
container.scrollTop = container.scrollHeight;
}
} catch (err) {
console.error('Error in scrollToBottom:', err);
// Fallback to direct property assignment if scrollTo fails
try {
container.scrollTop = container.scrollHeight;
} catch (e) { }
}
}; };
const scrollToBottomInstant = (container: HTMLElement) => { const scrollToBottomInstant = (container: HTMLElement | null | undefined) => {
container.scrollTop = container.scrollHeight; if (!container || typeof container !== 'object') return;
try {
container.scrollTop = container.scrollHeight;
} catch (e) { }
}; };
return { scrollToBottom, scrollToBottomInstant }; return { scrollToBottom, scrollToBottomInstant };

View File

@@ -1,4 +1,4 @@
{ {
"commitHash": "f0b89d6", "commitHash": "5e8ba7b",
"buildTime": "2026-01-13T10:09:36.925Z" "buildTime": "2026-01-14T05:59:07.483Z"
} }