From e951fa1ceeec6e836e80bf850b7e0f2b41d6a74e Mon Sep 17 00:00:00 2001 From: Fernando Gomes Date: Mon, 18 May 2026 16:49:42 +0000 Subject: [PATCH] perf(code): make task composer repo/branch selectors feel instant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new-task composer's branch dropdown was empty until the user clicked it and the trigger button stayed blank in the meantime — the cloud-branches query was gated on the picker being open. Reopening also refetched from scratch because the infinite query had no staleTime. The local-branch query in BranchSelector behaved the same way: gated on `open`, despite being a fast local git call. - Fetch cloud branches as soon as a repo is selected. The first page includes `default_branch`, so the branch button shows `main`/`master` immediately and the dropdown opens against a warm cache. - Add `staleTime: 5 min` to both `useGithubBranches` and `useUserGithubBranches`, matching the repository hooks. - Drop the `open` gate on local branches and bump `staleTime` to 60s. - Remove the now-dead `isCloudBranchPickerOpen` state in TaskInput. Generated-By: PostHog Code Task-Id: 3359bdaf-6661-4001-beab-9ad6478f3e28 --- .../git-interaction/components/BranchSelector.tsx | 2 +- .../features/task-detail/components/TaskInput.tsx | 9 --------- apps/code/src/renderer/hooks/useIntegrations.ts | 2 ++ 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/apps/code/src/renderer/features/git-interaction/components/BranchSelector.tsx b/apps/code/src/renderer/features/git-interaction/components/BranchSelector.tsx index 0ea81f965..19d306c09 100644 --- a/apps/code/src/renderer/features/git-interaction/components/BranchSelector.tsx +++ b/apps/code/src/renderer/features/git-interaction/components/BranchSelector.tsx @@ -107,7 +107,7 @@ export function BranchSelector({ useQuery( trpc.git.getAllBranches.queryOptions( { directoryPath: repoPath as string }, - { enabled: !isCloudMode && !!repoPath && open, staleTime: 10_000 }, + { enabled: !isCloudMode && !!repoPath, staleTime: 60_000 }, ), ); diff --git a/apps/code/src/renderer/features/task-detail/components/TaskInput.tsx b/apps/code/src/renderer/features/task-detail/components/TaskInput.tsx index d0302697d..b52c6b104 100644 --- a/apps/code/src/renderer/features/task-detail/components/TaskInput.tsx +++ b/apps/code/src/renderer/features/task-detail/components/TaskInput.tsx @@ -106,7 +106,6 @@ export function TaskInput({ const [cloudRepoSearchQuery, setCloudRepoSearchQuery] = useState(""); const [isCloudRepoPickerOpen, setIsCloudRepoPickerOpen] = useState(false); const [cloudBranchSearchQuery, setCloudBranchSearchQuery] = useState(""); - const [isCloudBranchPickerOpen, setIsCloudBranchPickerOpen] = useState(false); const [selectedEnvironment, setSelectedEnvironmentRaw] = useState< string | null >(null); @@ -244,7 +243,6 @@ export function TaskInput({ selectedInstallationId, selectedCloudRepository, cloudBranchSearchQuery, - isCloudBranchPickerOpen, ); const cloudBranches = cloudBranchData?.branches; const cloudDefaultBranch = cloudBranchData?.defaultBranch ?? null; @@ -324,10 +322,6 @@ export function TaskInput({ }); }, [refreshCloudBranches]); - const handleCloudBranchPickerOpen = useCallback(() => { - setIsCloudBranchPickerOpen(true); - }, []); - const handleCloudRepoPickerOpenChange = useCallback((open: boolean) => { setIsCloudRepoPickerOpen(open); if (!open) { @@ -344,7 +338,6 @@ export function TaskInput({ }, [loadMoreCloudRepositories]); const handleCloudBranchPickerClose = useCallback(() => { - setIsCloudBranchPickerOpen(false); setCloudBranchSearchQuery(""); }, []); @@ -414,7 +407,6 @@ export function TaskInput({ useEffect(() => { setCloudBranchSearchQuery(""); - setIsCloudBranchPickerOpen(false); }, []); const effectiveRepoPath = @@ -717,7 +709,6 @@ export function TaskInput({ cloudBranchesFetchingMore={cloudBranchesFetchingMore} cloudBranchesHasMore={cloudBranchesHasMore} cloudSearchQuery={cloudBranchSearchQuery} - onCloudPickerOpen={handleCloudBranchPickerOpen} onCloudPickerClose={handleCloudBranchPickerClose} onCloudSearchChange={handleCloudBranchSearchChange} onCloudLoadMore={handleLoadMoreCloudBranches} diff --git a/apps/code/src/renderer/hooks/useIntegrations.ts b/apps/code/src/renderer/hooks/useIntegrations.ts index c6d9ad9f6..b32cd2c63 100644 --- a/apps/code/src/renderer/hooks/useIntegrations.ts +++ b/apps/code/src/renderer/hooks/useIntegrations.ts @@ -392,6 +392,7 @@ export function useGithubBranches( if (!lastPage.hasMore) return undefined; return allPages.reduce((n, p) => n + p.branches.length, 0); }, + staleTime: 5 * 60 * 1000, }, ); @@ -460,6 +461,7 @@ export function useUserGithubBranches( if (!lastPage.hasMore) return undefined; return allPages.reduce((n, p) => n + p.branches.length, 0); }, + staleTime: 5 * 60 * 1000, }, );