Skip to content

Commit 92a7d3e

Browse files
committed
use correct hooks
1 parent 106843b commit 92a7d3e

3 files changed

Lines changed: 13 additions & 21 deletions

File tree

src/components/AffectedComponent.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
PURLInspectResponse,
77
VulnInPackage,
88
} from "@/types/api/api";
9-
import { FunctionComponent, useMemo, useState } from "react";
9+
import { FunctionComponent, useMemo } from "react";
1010
import EcosystemImage from "./common/EcosystemImage";
1111
import { beautifyPurl, extractVersion } from "@/utils/common";
1212
import { Badge } from "./ui/badge";
@@ -27,7 +27,6 @@ const fetcher = (url: string) => fetch(url).then((res) => res.json());
2727
const AffectedComponentDetails: FunctionComponent<{
2828
vuln: DetailedDependencyVulnDTO;
2929
}> = ({ vuln }) => {
30-
const [activeCVE, setActiveCVE] = useState<VulnInPackage | null>(null);
3130
const { theme } = useTheme();
3231

3332
const purl = vuln.componentPurl;
@@ -45,17 +44,13 @@ const AffectedComponentDetails: FunctionComponent<{
4544
revalidateOnReconnect: false,
4645
});
4746

48-
useSWR(data ? `matched-cve-${vuln.cveID}` : null, () => {
49-
if (data) {
50-
const matchedCVE = data.vulns.find(
51-
(vulnInPkg) => vuln.cveID === vulnInPkg.CVEID,
52-
);
53-
if (matchedCVE) {
54-
setActiveCVE(matchedCVE);
55-
}
56-
}
57-
return null;
58-
});
47+
// Compute the matched CVE from the fetched data
48+
const activeCVE = useMemo(() => {
49+
if (!data) return null;
50+
return (
51+
data.vulns.find((vulnInPkg) => vuln.cveID === vulnInPkg.CVEID) ?? null
52+
);
53+
}, [data, vuln.cveID]);
5954

6055
if (isLoading) {
6156
return (

src/components/DependencyGraph.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ const DependencyGraph: FunctionComponent<{
134134
const childrenLimitMapRef = useRef<Map<string, number>>(new Map());
135135

136136
// Compute direct dependencies with available patches
137-
const directDepsWithPatchesRef = useRef<Set<string>>(new Set());
138-
useMemo(() => {
139-
directDepsWithPatchesRef.current.clear();
137+
const directDepsWithPatches = useMemo(() => {
138+
const set = new Set<string>();
140139
vulns.forEach((vuln) => {
141140
// Check if this is a DetailedDependencyVulnDTO with directDependencyFixedVersion
142141
const detailedVuln = vuln as any;
@@ -146,9 +145,10 @@ const DependencyGraph: FunctionComponent<{
146145
detailedVuln.vulnerabilityPath.length > 0
147146
) {
148147
// The direct dependency is the first element in the path
149-
directDepsWithPatchesRef.current.add(detailedVuln.vulnerabilityPath[0]);
148+
set.add(detailedVuln.vulnerabilityPath[0]);
150149
}
151150
});
151+
return set;
152152
}, [vulns]);
153153

154154
if (childCountMapRef.current.size === 0) {
@@ -201,7 +201,7 @@ const DependencyGraph: FunctionComponent<{
201201
previousNodesRef.current,
202202
handleExpansionToggle,
203203
enableContextMenu,
204-
directDepsWithPatchesRef.current,
204+
directDepsWithPatches,
205205
);
206206
previousNodesRef.current = nodes;
207207

src/components/Quickfix.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ function renderQuickFixText(
9797
const Quickfix: FunctionComponent<{ vuln: DetailedDependencyVulnDTO }> = ({
9898
vuln,
9999
}) => {
100-
// console.log("Quickfix component received vuln:", vuln);
101-
console.log(vuln.vulnerabilityPath[0]);
102-
103100
const componentPurl = vuln.componentPurl;
104101
const directDependencyFixedVersion =
105102
vuln.directDependencyFixedVersion ?? undefined;

0 commit comments

Comments
 (0)