From 526e8e13ae22822f298b8fd518271f1bd300db80 Mon Sep 17 00:00:00 2001 From: dawn <90008@gaze.systems> Date: Thu, 21 May 2026 05:06:02 +0300 Subject: [PATCH] add preloading to file nav --- src/components/repo.tsx | 4 +++- src/pages/repo/code.tsx | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/components/repo.tsx b/src/components/repo.tsx index 872928e..d0f8223 100644 --- a/src/components/repo.tsx +++ b/src/components/repo.tsx @@ -421,9 +421,11 @@ export const OverviewFileRow: Component<{ icon: JSX.Element; lastCommit?: TreeEntry['last_commit']; class?: string; + onMouseEnter?: JSX.EventHandlerUnion; + onMouseLeave?: JSX.EventHandlerUnion; onClick?: JSX.EventHandlerUnion; }> = (props) => ( - +
{props.icon} {props.name} diff --git a/src/pages/repo/code.tsx b/src/pages/repo/code.tsx index 196bb69..09b4ef3 100644 --- a/src/pages/repo/code.tsx +++ b/src/pages/repo/code.tsx @@ -655,6 +655,33 @@ export const RepoCodePage: Component = () => { const entryPath = joinPath(treePath, entry.name); const directory = isDirectory(entry); const href = directory ? treeHref(repo, treeRef, entryPath) : blobHref(repo, treeRef, entryPath); + const currentRef = effectiveRef(); + + let hoverTimer: ReturnType | undefined; + + const handleMouseEnter = () => { + hoverTimer = setTimeout(() => { + if (!directory) { + queryClient.prefetchQuery({ + queryKey: ['blob', repo.repoDid, treeRef, entryPath], + queryFn: () => getRepoBlob(repo, treeRef, entryPath), + }); + return; + } + + queryClient.prefetchQuery({ + queryKey: ['repo-tree', repo.repoDid, currentRef, entryPath], + queryFn: async () => ({ + tree: await getRepoTree(repo, currentRef!, entryPath), + path: entryPath, + ref: currentRef!, + }), + }); + }, 30); + }; + const handleMouseLeave = () => { + clearTimeout(hoverTimer); + }; return ( { } lastCommit={entry.last_commit} class={pendingTreeHref() === href ? 'untangled-file-row-loading' : undefined} + onMouseEnter={handleMouseEnter} + onMouseLeave={handleMouseLeave} onClick={(event) => { if (directory) { if (shouldAnimateNavigation(event)) { -- 2.51.2