From 06426763c969b9f6704d954b67440fcdff3dedb1 Mon Sep 17 00:00:00 2001 From: Val Alexander Date: Sat, 4 Apr 2026 15:43:46 -0500 Subject: [PATCH] Refresh git status when draft threads mount - Invalidate the cached git status for local draft threads on mount - Surface upstream changes sooner instead of waiting for the next poll --- apps/web/src/components/BranchToolbar.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/BranchToolbar.tsx b/apps/web/src/components/BranchToolbar.tsx index a398cfcc9..c3a2d7050 100644 --- a/apps/web/src/components/BranchToolbar.tsx +++ b/apps/web/src/components/BranchToolbar.tsx @@ -1,9 +1,9 @@ import type { ThreadId } from "@okcode/contracts"; import { ArrowDownIcon, FolderIcon, GitForkIcon, LoaderIcon } from "lucide-react"; -import { useCallback } from "react"; +import { useCallback, useEffect } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { gitPullMutationOptions, gitStatusQueryOptions, invalidateGitQueries } from "../lib/gitReactQuery"; +import { gitPullMutationOptions, gitQueryKeys, gitStatusQueryOptions, invalidateGitQueries } from "../lib/gitReactQuery"; import { newCommandId } from "../lib/utils"; import { readNativeApi } from "../nativeApi"; import { useComposerDraftStore } from "../composerDraftStore"; @@ -121,6 +121,13 @@ export default function BranchToolbar({ const isBehindUpstream = behindCount > 0 && !hasServerThread; const pullMutation = useMutation(gitPullMutationOptions({ cwd: gitCwd, queryClient })); + // Force a fresh git-status fetch when a draft thread mounts so we catch + // upstream changes immediately instead of waiting for the next poll cycle. + useEffect(() => { + if (hasServerThread || !gitCwd) return; + void queryClient.invalidateQueries({ queryKey: gitQueryKeys.status(gitCwd) }); + }, [hasServerThread, gitCwd, queryClient]); + const handlePull = useCallback(() => { if (pullMutation.isPending) return; const promise = pullMutation.mutateAsync();