Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 13 additions & 4 deletions packages/web/src/hooks/usePrefetchFileSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@ 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({
fileName: path,
repository: repoName,
branch: revisionName,
}, domain)),
staleTime,
});
}, [queryClient, domain]);
}, debounceDelay);

return { prefetchFileSource };
}
17 changes: 13 additions & 4 deletions packages/web/src/hooks/usePrefetchFolderContents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -20,8 +28,9 @@ export const usePrefetchFolderContents = () => {
path,
}, domain)
),
staleTime,
});
}, [queryClient, domain]);
}, debounceDelay);

return { prefetchFolderContents };
}