Skip to content

Commit fc31d46

Browse files
committed
perf: add React.memo to heavy components for performance optimization
Wrap frequently re-rendered list item components with React.memo: - TaskCard (renders 10-50+ times in Kanban board) - DisplayConversationEntry (renders for every message in conversation) - DiffCard (renders once per changed file) - ProjectCard (renders in project grid) - TaskRelationshipCard (renders in relationship lists)
1 parent aaade9a commit fc31d46

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

frontend/src/components/DiffCard.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Diff } from 'shared/types';
22
import { DiffModeEnum, DiffView, SplitSide } from '@git-diff-view/react';
33
import { generateDiffFile, type DiffFile } from '@git-diff-view/file';
4-
import { useMemo } from 'react';
4+
import { memo, useMemo } from 'react';
55
import { useUserSystem } from '@/components/config-provider';
66
import { getHighLightLanguageFromPath } from '@/utils/extToLanguage';
77
import { getActualTheme } from '@/utils/theme';
@@ -69,7 +69,7 @@ function readPlainLine(
6969
}
7070
}
7171

72-
export default function DiffCard({
72+
const DiffCard = memo(function DiffCard({
7373
diff,
7474
expanded,
7575
onToggle,
@@ -323,4 +323,6 @@ export default function DiffCard({
323323
)}
324324
</div>
325325
);
326-
}
326+
});
327+
328+
export default DiffCard;

frontend/src/components/NormalizedConversation/DisplayConversationEntry.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { memo } from 'react';
12
import { useTranslation } from 'react-i18next';
23
import MarkdownRenderer from '@/components/ui/markdown-renderer.tsx';
34
import {
@@ -602,7 +603,7 @@ export const DisplayConversationEntryMaxWidth = (props: Props) => {
602603
);
603604
};
604605

605-
function DisplayConversationEntry({
606+
const DisplayConversationEntry = memo(function DisplayConversationEntry({
606607
entry,
607608
expansionKey,
608609
executionProcessId,
@@ -815,6 +816,6 @@ function DisplayConversationEntry({
815816
</div>
816817
</div>
817818
);
818-
}
819+
});
819820

820821
export default DisplayConversationEntryMaxWidth;

frontend/src/components/projects/ProjectCard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
Trash2,
2222
} from 'lucide-react';
2323
import { Project } from 'shared/types';
24-
import { useEffect, useRef } from 'react';
24+
import { memo, useEffect, useRef } from 'react';
2525
import { useTranslation } from 'react-i18next';
2626
import { useOpenProjectInEditor } from '@/hooks/useOpenProjectInEditor';
2727
import { useNavigateWithSearch } from '@/hooks';
@@ -35,7 +35,7 @@ type Props = {
3535
onEdit: (project: Project) => void;
3636
};
3737

38-
function ProjectCard({
38+
const ProjectCard = memo(function ProjectCard({
3939
project,
4040
isFocused,
4141
fetchProjects,
@@ -144,6 +144,6 @@ function ProjectCard({
144144
</CardHeader>
145145
</Card>
146146
);
147-
}
147+
});
148148

149149
export default ProjectCard;

frontend/src/components/tasks/TaskCard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useRef, useState } from 'react';
1+
import { memo, useCallback, useEffect, useRef, useState } from 'react';
22
import { KanbanCard } from '@/components/ui/shadcn-io/kanban';
33
import { CheckCircle, Loader2, XCircle, Play } from 'lucide-react';
44
import type { TaskWithAttemptStatus } from 'shared/types';
@@ -16,7 +16,7 @@ interface TaskCardProps {
1616
isOpen?: boolean;
1717
}
1818

19-
export function TaskCard({
19+
export const TaskCard = memo(function TaskCard({
2020
task,
2121
index,
2222
status,
@@ -125,4 +125,4 @@ export function TaskCard({
125125
</KanbanCard>
126126
</div>
127127
);
128-
}
128+
});

frontend/src/components/tasks/TaskRelationshipCard.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { memo } from 'react';
12
import { Card } from '@/components/ui/card';
23
import { Badge } from '@/components/ui/badge';
34
import { cn } from '@/lib/utils';
@@ -10,7 +11,7 @@ interface TaskRelationshipCardProps {
1011
className?: string;
1112
}
1213

13-
export function TaskRelationshipCard({
14+
export const TaskRelationshipCard = memo(function TaskRelationshipCard({
1415
task,
1516
isCurrentTask = false,
1617
onClick,
@@ -103,4 +104,4 @@ export function TaskRelationshipCard({
103104
</div>
104105
</Card>
105106
);
106-
}
107+
});

0 commit comments

Comments
 (0)