TypeScript
fix(web): default-branch confirmation keeps its copy while closing (#16907)
Otavio Salvador844a9812a001
diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsxindex 1b60f7179d3..23fe91ce6b0 100644--- a/apps/web/src/components/GitActionsControl.tsx+++ b/apps/web/src/components/GitActionsControl.tsx@@ -1008,6 +1008,8 @@ export default function GitActionsControl({const [inlineSuccess, setInlineSuccess] = useState<InlineGitActionSuccess | null>(null);const [pendingDefaultBranchAction, setPendingDefaultBranchAction] =useState<PendingDefaultBranchAction | null>(null);+ // Keep the payload until the dialog finishes closing.+ const [isDefaultBranchDialogOpen, setIsDefaultBranchDialogOpen] = useState(false);const sourceControlScope = { environmentId: activeEnvironmentId, cwd: gitCwd };const vcsActionState = useAtomValue(vcsActionManager.stateAtom(sourceControlScope));const visibleInlineSuccess = inlineSuccess?.scopeKey === successScopeKey ? inlineSuccess : null;@@ -1250,6 +1252,7 @@ export default function GitActionsControl({...(onConfirmed ? { onConfirmed } : {}),...(filePaths ? { filePaths } : {}),});+ setIsDefaultBranchDialogOpen(true);return;}onConfirmed?.();@@ -1359,29 +1362,18 @@ export default function GitActionsControl({}}- const continuePendingDefaultBranchAction = () => {- if (!pendingDefaultBranchAction) return;- const { action, commitMessage, onConfirmed, filePaths } = pendingDefaultBranchAction;- setPendingDefaultBranchAction(null);- void runGitActionWithToast({- action,- ...(commitMessage ? { commitMessage } : {}),- ...(onConfirmed ? { onConfirmed } : {}),- ...(filePaths ? { filePaths } : {}),- skipDefaultBranchPrompt: true,- });- };-- const checkoutFeatureBranchAndContinuePendingAction = () => {- if (!pendingDefaultBranchAction) return;+ const continuePendingDefaultBranchAction = (featureBranch: boolean) => {+ if (!isDefaultBranchDialogOpen || !pendingDefaultBranchAction || !canWriteSourceControl) return;+ if (featureBranch && (!canChangeThreadBranch || featureBranchUnavailableReason !== null))+ return;const { action, commitMessage, onConfirmed, filePaths } = pendingDefaultBranchAction;- setPendingDefaultBranchAction(null);+ setIsDefaultBranchDialogOpen(false);void runGitActionWithToast({action,...(commitMessage ? { commitMessage } : {}),...(onConfirmed ? { onConfirmed } : {}),...(filePaths ? { filePaths } : {}),- featureBranch: true,+ featureBranch,skipDefaultBranchPrompt: true,});};@@ -2041,11 +2033,10 @@ export default function GitActionsControl({/><Dialog- open={pendingDefaultBranchAction !== null}- onOpenChange={(open) => {- if (!open) {- setPendingDefaultBranchAction(null);- }+ open={isDefaultBranchDialogOpen}+ onOpenChange={setIsDefaultBranchDialogOpen}+ onOpenChangeComplete={(open) => {+ if (!open) setPendingDefaultBranchAction(null);}}><DialogPopup className="max-w-xl">@@ -2063,7 +2054,7 @@ export default function GitActionsControl({className="w-full sm:mr-auto sm:w-auto"variant="outline"size="sm"- onClick={() => setPendingDefaultBranchAction(null)}+ onClick={() => setIsDefaultBranchDialogOpen(false)}>Abort</Button>@@ -2071,7 +2062,7 @@ export default function GitActionsControl({className="w-full max-w-full sm:w-auto"variant="outline"size="sm-multiline"- onClick={continuePendingDefaultBranchAction}+ onClick={() => continuePendingDefaultBranchAction(false)}disabled={!canWriteSourceControl}>{pendingDefaultBranchActionCopy?.continueLabel ?? "Continue"}@@ -2079,7 +2070,7 @@ export default function GitActionsControl({<ButtonclassName="w-full max-w-full sm:w-auto"size="sm-multiline"- onClick={checkoutFeatureBranchAndContinuePendingAction}+ onClick={() => continuePendingDefaultBranchAction(true)}disabled={!canChangeThreadBranch || featureBranchUnavailableReason !== null}>Check out feature branch & continue