Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ interface CollapsedWorkspaceItemProps {
isActive: boolean;
isUnread: boolean;
workspaceStatus: ActivePaneStatus | null;
diffStats?: { additions: number; deletions: number } | null;
itemRef: RefObject<HTMLButtonElement | null>;
showDeleteDialog: boolean;
setShowDeleteDialog: (open: boolean) => void;
Expand All @@ -52,7 +51,6 @@ export function CollapsedWorkspaceItem({
isActive,
isUnread,
workspaceStatus,
diffStats,
itemRef,
showDeleteDialog,
setShowDeleteDialog,
Expand Down Expand Up @@ -172,7 +170,6 @@ export function CollapsedWorkspaceItem({
<WorkspaceHoverCardContent
workspaceId={id}
workspaceAlias={name}
diffStats={diffStats}
onEditBranchClick={setRenameBranchTarget}
/>
</HoverCardContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ interface WorkspaceContextMenuProps {
isUnread: boolean;
workspaceStatus: string | null | undefined;
sections: { id: string; name: string }[];
diffStats?: { additions: number; deletions: number } | null;
onRename: () => void;
onOpenInFinder: () => void;
onOpenInEditor: () => void;
Expand All @@ -67,7 +66,6 @@ export function WorkspaceContextMenu({
isUnread,
workspaceStatus,
sections,
diffStats,
onRename,
onOpenInFinder,
onOpenInEditor,
Expand Down Expand Up @@ -254,7 +252,6 @@ export function WorkspaceContextMenu({
<WorkspaceHoverCardContent
workspaceId={id}
workspaceAlias={name}
diffStats={diffStats}
onEditBranchClick={setRenameBranchTarget}
/>
</HoverCardContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,6 @@ export function WorkspaceListItem({
enabled: hasHovered && !!worktreePath,
staleTime: GITHUB_STATUS_STALE_TIME,
});
const localDiffStats = useMemo(() => {
if (!localChanges) return null;
const allFiles =
localChanges.againstBase.length > 0
? localChanges.againstBase
: [
...localChanges.staged,
...localChanges.unstaged,
...localChanges.untracked,
];
const additions = allFiles.reduce((sum, f) => sum + (f.additions || 0), 0);
const deletions = allFiles.reduce((sum, f) => sum + (f.deletions || 0), 0);
if (additions === 0 && deletions === 0) return null;
return { additions, deletions };
}, [localChanges]);

const { data: aheadBehind, refetch: refetchAheadBehind } =
electronTrpc.workspaces.getAheadBehind.useQuery(
Expand All @@ -191,6 +176,22 @@ export function WorkspaceListItem({
workspaceId: id,
});

const localDiffStats = useMemo(() => {
if (!localChanges) return null;
const allFiles =
localChanges.againstBase.length > 0
? localChanges.againstBase
: [
...localChanges.staged,
...localChanges.unstaged,
...localChanges.untracked,
];
const additions = allFiles.reduce((sum, f) => sum + (f.additions || 0), 0);
const deletions = allFiles.reduce((sum, f) => sum + (f.deletions || 0), 0);
if (additions === 0 && deletions === 0) return null;
return { additions, deletions };
}, [localChanges]);
Comment on lines 176 to +193
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Dead code: localDiffStats and diffStats are computed but never consumed

The localDiffStats memo and the diffStats derivation are both still present after the revert, but the diffStats prop was removed from both CollapsedWorkspaceItem and WorkspaceContextMenu, so nothing actually reads these values. The useMemo will still run on every localChanges change, wasting a small amount of compute on a hot render path.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceListItem.tsx
Line: 176-193

Comment:
**Dead code: `localDiffStats` and `diffStats` are computed but never consumed**

The `localDiffStats` memo and the `diffStats` derivation are both still present after the revert, but the `diffStats` prop was removed from both `CollapsedWorkspaceItem` and `WorkspaceContextMenu`, so nothing actually reads these values. The `useMemo` will still run on every `localChanges` change, wasting a small amount of compute on a hot render path.

How can I resolve this? If you propose a fix, please make it concise.


const handleClick = (e?: React.MouseEvent) => {
if (rename.isRenaming) return;

Expand Down Expand Up @@ -249,7 +250,11 @@ export function WorkspaceListItem({
};

const pr = githubStatus?.pr;
const diffStats = localDiffStats;
const diffStats =
localDiffStats ||
(pr && (pr.additions > 0 || pr.deletions > 0)
? { additions: pr.additions, deletions: pr.deletions }
: null);

const showBranchSubtitle = isBranchWorkspace || (!!name && name !== branch);

Expand All @@ -263,7 +268,6 @@ export function WorkspaceListItem({
isActive={isActive}
isUnread={isUnread}
workspaceStatus={workspaceStatus}
diffStats={diffStats}
itemRef={collapsedItemRef}
showDeleteDialog={showDeleteDialog}
setShowDeleteDialog={setShowDeleteDialog}
Expand Down Expand Up @@ -466,7 +470,6 @@ export function WorkspaceListItem({
isUnread={isUnread}
workspaceStatus={workspaceStatus}
sections={sections}
diffStats={diffStats}
onRename={rename.startRename}
onOpenInFinder={handleOpenInFinder}
onOpenInEditor={handleOpenInEditor}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ import { ReviewStatus } from "./components/ReviewStatus";
interface WorkspaceHoverCardContentProps {
workspaceId: string;
workspaceAlias?: string;
diffStats?: { additions: number; deletions: number } | null;
onEditBranchClick?: (branchName: string) => void;
}

export function WorkspaceHoverCardContent({
workspaceId,
workspaceAlias,
diffStats,
onEditBranchClick,
}: WorkspaceHoverCardContentProps) {
const { data: worktreeInfo } =
Expand Down Expand Up @@ -64,15 +62,6 @@ export function WorkspaceHoverCardContent({
</Button>
) : null;

const diffStatsBadge = diffStats ? (
<div className="flex items-center gap-1.5 text-xs font-mono shrink-0">
<span className="text-emerald-500">+{diffStats.additions}</span>
<span className="text-destructive-foreground">
-{diffStats.deletions}
</span>
</div>
) : null;

const needsRebase = worktreeInfo?.gitStatus?.needsRebase;
const behindCount = worktreeInfo?.gitStatus?.behind;

Expand Down Expand Up @@ -176,7 +165,12 @@ export function WorkspaceHoverCardContent({
/>
)}
</div>
{diffStatsBadge}
<div className="flex items-center gap-1.5 text-xs font-mono shrink-0">
<span className="text-emerald-500">+{pr.additions}</span>
<span className="text-destructive-foreground">
-{pr.deletions}
</span>
</div>
</div>

<p className="text-xs leading-relaxed line-clamp-2">{pr.title}</p>
Expand Down Expand Up @@ -214,18 +208,11 @@ export function WorkspaceHoverCardContent({
</div>
) : repoUrl ? (
<div className="pt-2 border-t border-border space-y-2">
<div className="flex items-center justify-between gap-2">
<div className="text-xs text-muted-foreground">
No PR for this branch
</div>
{diffStatsBadge}
<div className="text-xs text-muted-foreground">
No PR for this branch
</div>
{previewButton}
</div>
) : diffStatsBadge ? (
<div className="pt-2 border-t border-border flex items-center justify-end">
{diffStatsBadge}
</div>
) : null}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
LuRotateCw,
} from "react-icons/lu";
import { electronTrpc } from "renderer/lib/electron-trpc";
import { useHoverGitHubStatus } from "renderer/lib/githubQueryPolicy";
import { useWorkspaceDeleteHandler } from "renderer/react-query/workspaces/useWorkspaceDeleteHandler";
import { STROKE_WIDTH } from "../../WorkspaceSidebar/constants";
import { DeleteWorkspaceDialog } from "../../WorkspaceSidebar/WorkspaceListItem/components/DeleteWorkspaceDialog/DeleteWorkspaceDialog";
Expand All @@ -36,6 +37,12 @@ export function WorkspaceRow({
isOpening,
}: WorkspaceRowProps) {
const isBranch = workspace.type === "branch";
const { githubStatus, onMouseEnter: onGithubMouseEnter } =
useHoverGitHubStatus({
workspaceId: workspace.workspaceId,
surface: "workspace-row",
isWorktree: workspace.type === "worktree",
});
const { showDeleteDialog, setShowDeleteDialog, handleDeleteClick } =
useWorkspaceDeleteHandler();
const openFileInEditor = electronTrpc.external.openFileInEditor.useMutation({
Expand All @@ -52,6 +59,9 @@ export function WorkspaceRow({
}
};

const pr = githubStatus?.pr;
const showDiffStats = pr && (pr.additions > 0 || pr.deletions > 0);

const timeText = workspace.isOpen
? `Opened ${getRelativeTime(workspace.lastOpenedAt)}`
: `Created ${getRelativeTime(workspace.createdAt)}`;
Expand All @@ -69,6 +79,7 @@ export function WorkspaceRow({
type="button"
onClick={handleClick}
disabled={isOpening}
onMouseEnter={onGithubMouseEnter}
className={cn(
"flex items-center gap-3 w-full px-4 py-2 group text-left",
"hover:bg-background/50 transition-colors",
Expand Down Expand Up @@ -134,6 +145,14 @@ export function WorkspaceRow({
</span>
)}

{/* Diff stats */}
{showDiffStats && (
<div className="flex items-center gap-1 text-[10px] font-mono shrink-0">
<span className="text-emerald-500">+{pr.additions}</span>
<span className="text-destructive-foreground">-{pr.deletions}</span>
</div>
)}

{/* Spacer */}
<div className="flex-1" />

Expand Down
Loading