Skip to content

Commit

Permalink
Reduce SidebarLinksData render time
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Sep 7, 2023
1 parent b47663e commit 2c14b62
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/pages/home/sidebar/SidebarLinksData.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,24 @@ function SidebarLinksData({isFocused, allReportActions, betas, chatReports, curr
const reportIDsRef = useRef(null);
const isLoading = SessionUtils.didUserLogInDuringSession() && isLoadingReportData;
const optionListItems = useMemo(() => {
const reportIDs = SidebarUtils.getOrderedReportIDs(currentReportID, chatReports, betas, policies, priorityMode, allReportActions);
const reportIDs = SidebarUtils.getOrderedReportIDs(null, chatReports, betas, policies, priorityMode, allReportActions);
if (deepEqual(reportIDsRef.current, reportIDs)) {
return reportIDsRef.current;
}

// We need to update existing reports only once while loading because they are updated several times during loading and causes this regression: https://github.com/Expensify/App/issues/24596#issuecomment-1681679531
if (!isLoading || !reportIDsRef.current || (_.isEmpty(reportIDsRef.current) && currentReportID)) {
if (!isLoading || !reportIDsRef.current) {
reportIDsRef.current = reportIDs;
}
return reportIDsRef.current || [];
}, [allReportActions, betas, chatReports, currentReportID, policies, priorityMode, isLoading]);
}, [allReportActions, betas, chatReports, policies, priorityMode, isLoading]);

const optionListItemsWithCurrentReport = useMemo(() => {
if (currentReportID && !_.contains(optionListItems, currentReportID)) {
return [currentReportID, ...optionListItems];
}
return optionListItems;
}, [optionListItems, currentReportID]);

return (
<View
Expand All @@ -95,7 +102,7 @@ function SidebarLinksData({isFocused, allReportActions, betas, chatReports, curr
priorityMode={priorityMode}
// Data props:
isLoading={isLoading}
optionListItems={optionListItems}
optionListItems={optionListItemsWithCurrentReport}
/>
</View>
);
Expand Down

0 comments on commit 2c14b62

Please sign in to comment.