From a77c4caea7f912ea69f9639f85257c85004a26a8 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Mar 2026 12:05:04 -0700 Subject: [PATCH] Use effect event for git action toast flow - Replace the ref indirection with `useEffectEvent` - Keep push and PR actions wired to the latest toast state --- apps/web/src/components/GitActionsControl.tsx | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsx index 073c944460..10bceacb57 100644 --- a/apps/web/src/components/GitActionsControl.tsx +++ b/apps/web/src/components/GitActionsControl.tsx @@ -5,7 +5,7 @@ import type { ThreadId, } from "@t3tools/contracts"; import { useIsMutating, useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { useCallback, useEffect, useEffectEvent, useMemo, useRef, useState } from "react"; import { ChevronDownIcon, CloudUploadIcon, GitCommitIcon, InfoIcon } from "lucide-react"; import { GitHubIcon } from "./Icons"; import { @@ -218,9 +218,6 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions const [pendingDefaultBranchAction, setPendingDefaultBranchAction] = useState(null); const activeGitActionProgressRef = useRef(null); - const runGitActionWithToastRef = useRef<((input: RunGitActionWithToastInput) => void) | null>( - null, - ); const updateActiveProgressToast = useCallback(() => { const progress = activeGitActionProgressRef.current; @@ -407,7 +404,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions }); }, [gitStatusForActions, threadToastData]); - const runGitActionWithToast = useCallback( + const runGitActionWithToast = useEffectEvent( async ({ action, commitMessage, @@ -532,7 +529,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions actionProps: { children: "Push", onClick: () => { - runGitActionWithToastRef.current?.({ + void runGitActionWithToast({ action: "commit_push", forcePushOnlyProgress: true, onConfirmed: closeResultToast, @@ -560,7 +557,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions children: "Create PR", onClick: () => { closeResultToast(); - runGitActionWithToastRef.current?.({ + void runGitActionWithToast({ action: "commit_push_pr", forcePushOnlyProgress: true, statusOverride: actionStatus, @@ -581,15 +578,8 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions }); } }, - [gitStatusForActions, isDefaultBranch, runImmediateGitActionMutation, threadToastData], ); - useEffect(() => { - runGitActionWithToastRef.current = (input) => { - void runGitActionWithToast(input); - }; - }, [runGitActionWithToast]); - const continuePendingDefaultBranchAction = useCallback(() => { if (!pendingDefaultBranchAction) return; const { action, commitMessage, forcePushOnlyProgress, onConfirmed, filePaths } =