Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,34 @@ function MoneyRequestReportNavigation({reportID, shouldDisplayNarrowVersion}: Mo
const archivedReportsIdSet = useArchivedReportsIdSet();

const {type, status, sortBy, sortOrder, groupBy} = lastSearchQuery?.queryJSON ?? {};
let results: Array<string | undefined> = [];
if (!!type && !!currentSearchResults?.data && !!currentSearchResults?.search) {

const searchResultsData = currentSearchResults?.data;
const searchResultsSearch = currentSearchResults?.search;
const currentAccountID = currentUserDetails.accountID;
const currentUserEmail = currentUserDetails.email ?? '';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By extracting the specific sub-fields needed (.data, .accountID, etc.) into separate variables, the compiler now tracks only the fields actually used, so the computation only re-runs when its real inputs change.

This is a fairly subtle implementation that leads to a great improvement. I'm wondering if we have a best practice for documenting these scenarios yet? It seems relatively easy to perhaps reverse this change if you view these as unnecessary when actually they are signals for React compiler 🤔

Should we add something like:

// React Compiler: destructure to narrow reactive dependencies and avoid recomputes on unrelated changes

const searchKey = lastSearchQuery?.searchKey;

let allReports: Array<string | undefined> = [];
if (!!type && !!searchResultsData && !!searchResultsSearch) {
const [searchData] = getSections({
type,
data: currentSearchResults.data,
currentAccountID: currentUserDetails.accountID,
currentUserEmail: currentUserDetails.email ?? '',
data: searchResultsData,
currentAccountID,
currentUserEmail,
translate,
formatPhoneNumber,
bankAccountList,
groupBy,
reportActions: exportReportActions,
currentSearch: lastSearchQuery?.searchKey,
currentSearch: searchKey,
archivedReportsIDList: archivedReportsIdSet,
isActionLoadingSet,
cardFeeds,
allReportMetadata,
cardList,
});
results = getSortedSections(type, status ?? '', searchData, localeCompare, translate, sortBy, sortOrder, groupBy).map((value) => value.reportID);
allReports = getSortedSections(type, status ?? '', searchData, localeCompare, translate, sortBy, sortOrder, groupBy).map((value) => value.reportID);
}
const allReports = results;

const currentIndex = allReports.indexOf(reportID);
const allReportsCount = lastSearchQuery?.previousLengthOfResults ?? 0;
Expand Down
Loading