Skip to content

Commit ba0cf9a

Browse files
Use useMemo for callback passed to SarifLocation.onClick in AlertTablePathNodeRow
1 parent 443c9ac commit ba0cf9a

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

extensions/ql-vscode/src/view/results/AlertTablePathNodeRow.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as Keys from "./result-keys";
44
import { SarifLocation } from "./locations/SarifLocation";
55
import { selectableZebraStripe } from "./result-table-utils";
66
import { ScrollIntoViewHelper } from "./scroll-into-view-helper";
7+
import { useMemo } from "react";
78

89
interface Props {
910
step: Sarif.ThreadFlowLocation;
@@ -32,11 +33,19 @@ export function AlertTablePathNodeRow(props: Props) {
3233
scroller,
3334
} = props;
3435

35-
const pathNodeKey: Keys.PathNode = {
36-
resultIndex,
37-
pathIndex,
38-
pathNodeIndex,
39-
};
36+
const pathNodeKey: Keys.PathNode = useMemo(
37+
() => ({
38+
resultIndex,
39+
pathIndex,
40+
pathNodeIndex,
41+
}),
42+
[pathIndex, pathNodeIndex, resultIndex],
43+
);
44+
const handleSarifLocationClicked = useMemo(
45+
() => updateSelectionCallback(pathNodeKey),
46+
[pathNodeKey, updateSelectionCallback],
47+
);
48+
4049
const isSelected = Keys.equalsNotUndefined(selectedItem, pathNodeKey);
4150
const stepIndex = pathNodeIndex + 1; // Convert to 1-based
4251
const zebraIndex = resultIndex + stepIndex;
@@ -67,7 +76,7 @@ export function AlertTablePathNodeRow(props: Props) {
6776
loc={step.location}
6877
sourceLocationPrefix={sourceLocationPrefix}
6978
databaseUri={databaseUri}
70-
onClick={updateSelectionCallback(pathNodeKey)}
79+
onClick={handleSarifLocationClicked}
7180
/>
7281
) : (
7382
"[no location]"
@@ -85,7 +94,7 @@ export function AlertTablePathNodeRow(props: Props) {
8594
loc={step.location}
8695
sourceLocationPrefix={sourceLocationPrefix}
8796
databaseUri={databaseUri}
88-
onClick={updateSelectionCallback(pathNodeKey)}
97+
onClick={handleSarifLocationClicked}
8998
/>
9099
)}
91100
</td>

0 commit comments

Comments
 (0)