From 29c472a91c81218b552510e8d2da278e638c94a0 Mon Sep 17 00:00:00 2001 From: bkellam Date: Wed, 11 Jun 2025 11:24:57 -0700 Subject: [PATCH 1/2] Add debounce --- packages/web/src/hooks/usePrefetchFileSource.ts | 17 +++++++++++++---- .../web/src/hooks/usePrefetchFolderContents.ts | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/web/src/hooks/usePrefetchFileSource.ts b/packages/web/src/hooks/usePrefetchFileSource.ts index 755d7fdb9..de9cce34f 100644 --- a/packages/web/src/hooks/usePrefetchFileSource.ts +++ b/packages/web/src/hooks/usePrefetchFileSource.ts @@ -4,13 +4,21 @@ import { useQueryClient } from "@tanstack/react-query"; import { useDomain } from "./useDomain"; import { unwrapServiceError } from "@/lib/utils"; import { getFileSource } from "@/features/search/fileSourceApi"; -import { useCallback } from "react"; +import { useDebounceCallback } from "usehooks-ts"; -export const usePrefetchFileSource = () => { +interface UsePrefetchFileSourceProps { + debounceDelay?: number; + staleTime?: number; +} + +export const usePrefetchFileSource = ({ + debounceDelay = 200, + staleTime = 5 * 60 * 1000, // 5 minutes +}: UsePrefetchFileSourceProps = {}) => { const queryClient = useQueryClient(); const domain = useDomain(); - const prefetchFileSource = useCallback((repoName: string, revisionName: string, path: string) => { + const prefetchFileSource = useDebounceCallback((repoName: string, revisionName: string, path: string) => { queryClient.prefetchQuery({ queryKey: ['fileSource', repoName, revisionName, path, domain], queryFn: () => unwrapServiceError(getFileSource({ @@ -18,8 +26,9 @@ export const usePrefetchFileSource = () => { repository: repoName, branch: revisionName, }, domain)), + staleTime, }); - }, [queryClient, domain]); + }, debounceDelay); return { prefetchFileSource }; } \ No newline at end of file diff --git a/packages/web/src/hooks/usePrefetchFolderContents.ts b/packages/web/src/hooks/usePrefetchFolderContents.ts index 8bbcc5f8d..e135cb7a1 100644 --- a/packages/web/src/hooks/usePrefetchFolderContents.ts +++ b/packages/web/src/hooks/usePrefetchFolderContents.ts @@ -3,14 +3,22 @@ import { useQueryClient } from "@tanstack/react-query"; import { useDomain } from "./useDomain"; import { unwrapServiceError } from "@/lib/utils"; -import { useCallback } from "react"; import { getFolderContents } from "@/features/fileTree/actions"; +import { useDebounceCallback } from "usehooks-ts"; -export const usePrefetchFolderContents = () => { +interface UsePrefetchFolderContentsProps { + debounceDelay?: number; + staleTime?: number; +} + +export const usePrefetchFolderContents = ({ + debounceDelay = 200, + staleTime = 5 * 60 * 1000, // 5 minutes +}: UsePrefetchFolderContentsProps = {}) => { const queryClient = useQueryClient(); const domain = useDomain(); - const prefetchFolderContents = useCallback((repoName: string, revisionName: string, path: string) => { + const prefetchFolderContents = useDebounceCallback((repoName: string, revisionName: string, path: string) => { queryClient.prefetchQuery({ queryKey: ['tree', repoName, revisionName, path, domain], queryFn: () => unwrapServiceError( @@ -20,8 +28,9 @@ export const usePrefetchFolderContents = () => { path, }, domain) ), + staleTime, }); - }, [queryClient, domain]); + }, debounceDelay); return { prefetchFolderContents }; } \ No newline at end of file From 29352cfd08d2f39980a66ad3df9ffb6dc0b36142 Mon Sep 17 00:00:00 2001 From: bkellam Date: Wed, 11 Jun 2025 11:34:58 -0700 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f45b25ed3..8cc9391c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Text highlighting clarity. [#342](https://github.com/sourcebot-dev/sourcebot/pull/342) - Fixed repo list column header styling. [#344](https://github.com/sourcebot-dev/sourcebot/pull/344) - Clean up successful and failed jobs in Redis queues. [#343](https://github.com/sourcebot-dev/sourcebot/pull/343) +- Fixed issue with files occasionally not loading after moving the cursor rapidly over the file browser. [#346](https://github.com/sourcebot-dev/sourcebot/pull/346) ## [4.2.0] - 2025-06-09