Skip to content

Commit 7e0fd55

Browse files
causand22gabaker
authored andcommitted
fix(ui): Unnecessary re-renders and requests in file results component
Fixed an issue with file results re-rendering on any scroll in the window. `parsedResults` was a cloned object and had elements deleted on every render. Changing to a memoized filter prevents re-renders of the entire results list every scroll (as inViewElements will change on a scroll).
1 parent bc6cb92 commit 7e0fd55

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

ui/src/components/pages/files/Results.jsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect, useState, useMemo } from 'react';
22
import { Alert } from 'react-bootstrap';
33

44
// project imports
@@ -36,7 +36,6 @@ const ResultsTableOfContents = ({ parsedResults, inViewElements }) => {
3636
};
3737

3838
const Results = ({ sha256, results, setResults, numResults, setNumResults }) => {
39-
const parsedResults = structuredClone(results);
4039
// whether content is currently loading
4140
const [loading, setLoading] = useState(false);
4241
const [inViewElements, setInViewElements] = useState([]);
@@ -73,14 +72,14 @@ const Results = ({ sha256, results, setResults, numResults, setNumResults }) =>
7372
}
7473
};
7574

76-
// remove hidden display typed results from results object
77-
Object.keys(parsedResults)
78-
.sort()
79-
.map((image) => {
80-
if (parsedResults[image][0]['display_type'] && results[image][0]['display_type'] == 'Hidden') {
81-
delete parsedResults[image];
82-
}
83-
});
75+
const parsedResults = useMemo(() => {
76+
if (!results || typeof results !== 'object') return {};
77+
return Object.fromEntries(
78+
Object.entries(results).filter(([_, image]) => {
79+
return (!(image[0].display_type && image[0].display_type == 'Hidden'))
80+
})
81+
)
82+
}, [results])
8483

8584
return (
8685
<div id="results-tab" className="navbar-scroll-offset results-container">

0 commit comments

Comments
 (0)