From 47f26e99db46347887eed6479d204e4fecbcc414 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Sat, 9 May 2026 23:28:46 +0800 Subject: [PATCH] fix(app): redirect optimistically when archiving worktree from toolbar (#852) The toolbar archive deferred its redirect until the server confirmed the archive, so users briefly landed on the "workspace not found" gate and were then sent to the main checkout's workspace route. Mirror the sidebar pattern: synchronously router.replace to the project's new workspace screen up front and let archive reconcile only update the store. --- packages/app/src/git/use-actions.ts | 31 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/app/src/git/use-actions.ts b/packages/app/src/git/use-actions.ts index a94713c0c..d72117433 100644 --- a/packages/app/src/git/use-actions.ts +++ b/packages/app/src/git/use-actions.ts @@ -1,14 +1,16 @@ import { useState, useCallback, useEffect, useMemo, type ReactElement } from "react"; +import { router, type Href } from "expo-router"; import AsyncStorage from "@react-native-async-storage/async-storage"; import { type CheckoutGitActionStatus, useCheckoutGitActionsStore } from "@/git/actions-store"; import { type CheckoutStatusPayload, useCheckoutStatusQuery } from "@/git/use-status-query"; import { type CheckoutPrStatusPayload, useCheckoutPrStatusQuery } from "@/git/use-pr-status-query"; import { buildGitActions, narrowPullRequestState, type GitActions } from "@/git/policy"; import type { CheckoutPrMergeMethod } from "@server/shared/messages"; -import { resolveNewAgentWorkingDir } from "@/utils/new-agent-routing"; import { openExternalUrl } from "@/utils/open-external-url"; import { useToast } from "@/contexts/toast-context"; -import { navigateToWorkspace } from "@/hooks/use-workspace-navigation"; +import { useSessionStore } from "@/stores/session-store"; +import { resolveWorkspaceIdByExecutionDirectory } from "@/utils/workspace-execution"; +import { buildWorkspaceArchiveRedirectRoute } from "@/utils/workspace-archive-navigation"; export type { GitActionId, GitAction, GitActions } from "@/git/policy"; @@ -393,15 +395,22 @@ export function useGitActions({ serverId, cwd, icons }: UseGitActionsInput): Use toast.error("Worktree path unavailable"); return; } - const targetWorkingDir = resolveNewAgentWorkingDir(cwd, status ?? null); - void runArchiveWorktree({ serverId, cwd, worktreePath }) - .then(() => { - navigateToWorkspace(serverId, targetWorkingDir); - return; - }) - .catch((err) => { - toastActionError(err, "Failed to archive worktree"); - }); + const workspaces = useSessionStore.getState().sessions[serverId]?.workspaces; + const archivedWorkspaceId = + resolveWorkspaceIdByExecutionDirectory({ + workspaces: workspaces?.values(), + workspaceDirectory: worktreePath, + }) ?? worktreePath; + router.replace( + buildWorkspaceArchiveRedirectRoute({ + serverId, + archivedWorkspaceId, + workspaces: workspaces?.values() ?? [], + }) as Href, + ); + void runArchiveWorktree({ serverId, cwd, worktreePath }).catch((err) => { + toastActionError(err, "Failed to archive worktree"); + }); }, [cwd, runArchiveWorktree, serverId, status, toast, toastActionError]); const baseRefLabel = useMemo(() => formatBaseRefLabel(baseRef), [baseRef]);