Skip to content

Commit a77a4b5

Browse files
committed
fix: compute envModeItems dynamically so trigger label matches dropdown label
The envModeItems array was a static module-level constant that always resolved the 'local' label to 'Current checkout'. When a worktree is active, the dropdown item rendered 'Current worktree' via resolveCurrentWorkspaceLabel(), creating a mismatch with the trigger. Move envModeItems inside the component as a useMemo that depends on activeWorktreePath, using resolveCurrentWorkspaceLabel() for the local item label so both the trigger and dropdown stay in sync.
1 parent 638670c commit a77a4b5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

apps/web/src/components/BranchToolbarEnvModeSelector.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FolderIcon, GitForkIcon } from "lucide-react";
2-
import { memo } from "react";
2+
import { memo, useMemo } from "react";
33

44
import {
55
resolveCurrentWorkspaceLabel,
@@ -16,11 +16,6 @@ import {
1616
SelectValue,
1717
} from "./ui/select";
1818

19-
const envModeItems = [
20-
{ value: "local", label: resolveEnvModeLabel("local") },
21-
{ value: "worktree", label: resolveEnvModeLabel("worktree") },
22-
] as const;
23-
2419
interface BranchToolbarEnvModeSelectorProps {
2520
envLocked: boolean;
2621
effectiveEnvMode: EnvMode;
@@ -34,6 +29,14 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
3429
activeWorktreePath,
3530
onEnvModeChange,
3631
}: BranchToolbarEnvModeSelectorProps) {
32+
const envModeItems = useMemo(
33+
() => [
34+
{ value: "local" as const, label: resolveCurrentWorkspaceLabel(activeWorktreePath) },
35+
{ value: "worktree" as const, label: resolveEnvModeLabel("worktree") },
36+
],
37+
[activeWorktreePath],
38+
);
39+
3740
if (envLocked) {
3841
return (
3942
<span className="inline-flex items-center gap-1 border border-transparent px-[calc(--spacing(3)-1px)] text-sm font-medium text-muted-foreground/70 sm:text-xs">

0 commit comments

Comments
 (0)