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();