From ea7772efc63cf21d87da2e744a16633cfb68ee1b Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 29 May 2026 20:58:29 -0700 Subject: [PATCH] fix: cancel file explorer auto reveal frame (#3445) --- .../right-sidebar/useFileExplorerAutoReveal.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/right-sidebar/useFileExplorerAutoReveal.ts b/src/renderer/src/components/right-sidebar/useFileExplorerAutoReveal.ts index 81ffb9a23fd..3d95e3d8e50 100644 --- a/src/renderer/src/components/right-sidebar/useFileExplorerAutoReveal.ts +++ b/src/renderer/src/components/right-sidebar/useFileExplorerAutoReveal.ts @@ -1,4 +1,4 @@ -import { useEffect, useRef } from 'react' +import { useCallback, useEffect, useRef } from 'react' import type { Virtualizer } from '@tanstack/react-virtual' import { useAppStore } from '@/store' import type { OpenFile } from '@/store/slices/editor' @@ -36,6 +36,17 @@ export function useFileExplorerAutoReveal({ virtualizer }: UseFileExplorerAutoRevealParams): void { const prevActiveFileIdRef = useRef(null) + const scrollFrameRef = useRef(null) + + const cancelScrollFrame = useCallback((): void => { + if (scrollFrameRef.current === null) { + return + } + cancelAnimationFrame(scrollFrameRef.current) + scrollFrameRef.current = null + }, []) + + useEffect(() => cancelScrollFrame, [cancelScrollFrame]) useEffect(() => { if (activeFileId === prevActiveFileIdRef.current) { @@ -71,7 +82,9 @@ export function useFileExplorerAutoReveal({ setSelectedPath(filePath) const targetIndex = flatRows.findIndex((row) => row.path === filePath) if (targetIndex !== -1) { - requestAnimationFrame(() => { + cancelScrollFrame() + scrollFrameRef.current = requestAnimationFrame(() => { + scrollFrameRef.current = null virtualizer.scrollToIndex(targetIndex, { align: 'auto' }) }) } @@ -90,6 +103,7 @@ export function useFileExplorerAutoReveal({ }, [ activeFileId, activeWorktreeId, + cancelScrollFrame, worktreePath, pendingExplorerReveal, openFiles,