fix: prefetch under the exact cache key the page will read

Sidebar and Landing were calling prefetchWorkItems with no query, warming
the cache at '::'' which NewWorkspacePage never reads. Pass the user's
default-preset query so hover-prefetch actually hits the key the page
looks up on mount.
This commit is contained in:
Neil 2026-04-16 21:59:59 -07:00
parent b126a9fdd0
commit 1bdbb50cc4
2 changed files with 14 additions and 5 deletions

View file

@ -3,6 +3,7 @@ import { AlertTriangle, ExternalLink, FolderPlus, GitBranchPlus, Star } from 'lu
import { cn } from '../lib/utils'
import { useAppStore } from '../store'
import { isGitRepoKind } from '../../../shared/repo-kind'
import { getTaskPresetQuery } from '../lib/new-workspace'
import { ShortcutKeyCombo } from './ShortcutKeyCombo'
import logo from '../../../../resources/logo.svg'
@ -151,18 +152,20 @@ export default function Landing(): React.JSX.Element {
const openNewWorkspacePage = useAppStore((s) => s.openNewWorkspacePage)
const openModal = useAppStore((s) => s.openModal)
const prefetchWorkItems = useAppStore((s) => s.prefetchWorkItems)
const defaultTaskViewPreset = useAppStore((s) => s.settings?.defaultTaskViewPreset ?? 'all')
const canCreateWorktree = repos.some((repo) => isGitRepoKind(repo))
// Why: warm the work-item cache on hover/focus so clicking "Create Worktree"
// lands on a list that's already loaded.
// Why: warm the exact cache key NewWorkspacePage will read on mount — the
// default-preset query must match or the page pays a full round-trip after
// click.
const handlePrefetchNewWorkspace = (): void => {
if (!canCreateWorktree) {
return
}
const firstGit = repos.find((r) => isGitRepoKind(r))
if (firstGit?.path) {
prefetchWorkItems(firstGit.path)
prefetchWorkItems(firstGit.path, 36, getTaskPresetQuery(defaultTaskViewPreset))
}
}

View file

@ -4,6 +4,7 @@ import { useAppStore } from '@/store'
import { Button } from '@/components/ui/button'
import { Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip'
import { isGitRepoKind } from '../../../../shared/repo-kind'
import { getTaskPresetQuery } from '@/lib/new-workspace'
import {
DropdownMenu,
DropdownMenuContent,
@ -50,6 +51,7 @@ const SidebarHeader = React.memo(function SidebarHeader() {
// or is already in-flight. Shaves ~200600ms off perceived page-load latency.
const prefetchWorkItems = useAppStore((s) => s.prefetchWorkItems)
const activeRepoId = useAppStore((s) => s.activeRepoId)
const defaultTaskViewPreset = useAppStore((s) => s.settings?.defaultTaskViewPreset ?? 'all')
const handlePrefetch = React.useCallback(() => {
if (!canCreateWorktree) {
return
@ -57,9 +59,13 @@ const SidebarHeader = React.memo(function SidebarHeader() {
const activeRepo = repos.find((r) => r.id === activeRepoId && isGitRepoKind(r))
const firstGitRepo = activeRepo ?? repos.find((r) => isGitRepoKind(r))
if (firstGitRepo?.path) {
prefetchWorkItems(firstGitRepo.path)
// Why: warm the exact cache key the page will read on mount — must
// match NewWorkspacePage's `initialTaskQuery` derived from the same
// default preset, otherwise the prefetch lands in a key the page
// never reads and we pay the full round-trip after click.
prefetchWorkItems(firstGitRepo.path, 36, getTaskPresetQuery(defaultTaskViewPreset))
}
}, [activeRepoId, canCreateWorktree, prefetchWorkItems, repos])
}, [activeRepoId, canCreateWorktree, defaultTaskViewPreset, prefetchWorkItems, repos])
return (
<div className="flex items-center justify-between px-4 pt-3 pb-1">