Skip to content

Commit 8d7a797

Browse files
fix: prevent multiple refreshes on long scroll gestures
Add isRefreshingRef to block rapid-fire wheel events during refresh. This prevents a long continuous scroll from triggering multiple consecutive refreshes. Co-authored-by: Anthony <AnthonyRonning@users.noreply.github.com>
1 parent 7ac022f commit 8d7a797

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎frontend/src/components/ChatHistoryList.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export function ChatHistoryList({
9090
constisPulling=useRef(false);
9191
constpullDistanceRef=useRef(0);
9292
constwheelDeltaAccumulator=useRef(0);
93+
constisRefreshingRef=useRef(false);
9394

9495
// Fetch initial conversations from API using the OpenSecret SDK
9596
const{ isPending, error }=useQuery({
@@ -184,6 +185,8 @@ export function ChatHistoryList({
184185

185186
// Pull-to-refresh handler
186187
consthandleRefresh=useCallback(async()=>{
188+
// Set ref immediately to block rapid-fire events
189+
isRefreshingRef.current=true;
187190
setIsPullRefreshing(true);
188191
try{
189192
awaitpollForUpdates();
@@ -194,6 +197,7 @@ export function ChatHistoryList({
194197
setTimeout(()=>{
195198
setIsPullRefreshing(false);
196199
setPullDistance(0);
200+
isRefreshingRef.current=false;
197201
},300);
198202
}
199203
},[pollForUpdates]);
@@ -291,7 +295,7 @@ export function ChatHistoryList({
291295
constWHEEL_THRESHOLD=-50;// Require accumulated scroll before triggering
292296

293297
consthandleWheel=(e: WheelEvent)=>{
294-
if(!isDesktopPlatform||isPullRefreshing)return;
298+
if(!isDesktopPlatform||isRefreshingRef.current)return;
295299

296300
// Only handle if the event target is within our container
297301
if(!container.contains(e.targetasNode))return;
@@ -352,7 +356,7 @@ export function ChatHistoryList({
352356
window.removeEventListener("mouseup",handleMouseUp);
353357
}
354358
};
355-
},[containerRef,isPullRefreshing,handleRefresh]);
359+
},[containerRef,handleRefresh]);
356360

357361
// Set up polling every 60 seconds
358362
useEffect(()=>{

0 commit comments

Comments
 (0)