Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,10 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
);
},
[
reportAttributes,
reports,
reportNameValuePairs,
reportActions,
isOffline,
reportAttributes,
policy,
transactions,
draftComments,
Expand Down
7 changes: 7 additions & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {deepEqual} from 'fast-equals';
import React, {useMemo, useRef} from 'react';
import {useCurrentReportIDState} from '@hooks/useCurrentReportID';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useGetExpensifyCardFromReportAction from '@hooks/useGetExpensifyCardFromReportAction';
import useOnyx from '@hooks/useOnyx';
import usePrevious from '@hooks/usePrevious';
Expand Down Expand Up @@ -53,6 +54,8 @@ function OptionRowLHNData({
const [movedFromReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(lastAction, CONST.REPORT.MOVE_TYPE.FROM)}`);
const [movedToReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(lastAction, CONST.REPORT.MOVE_TYPE.TO)}`);
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const {login} = useCurrentUserPersonalDetails();
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${fullReport?.policyID}`);
// Check the report errors equality to avoid re-rendering when there are no changes
const prevReportErrors = usePrevious(reportAttributes?.reportErrors);
const areReportErrorsEqual = useMemo(() => deepEqual(prevReportErrors, reportAttributes?.reportErrors), [prevReportErrors, reportAttributes?.reportErrors]);
Expand Down Expand Up @@ -82,6 +85,8 @@ function OptionRowLHNData({
movedToReport,
currentUserAccountID,
reportAttributesDerived,
policyTags,
currentUserLogin: login,
Comment on lines +88 to +89

Choose a reason for hiding this comment

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

P2 Badge Include policy tags/login in memo dependencies

OptionRowLHNData now feeds policyTags and currentUserLogin into SidebarUtils.getOptionData, but the enclosing useMemo dependency list was not updated. When policy tags load asynchronously from Onyx (a common first-render path) or the current login changes, the memoized option data can stay stale and keep showing outdated modified-expense preview text until an unrelated dependency changes. Please add these new inputs to the memo dependencies so rows re-evaluate immediately when this data updates.

Useful? React with 👍 / 👎.

});
if (deepEqual(item, optionItemRef.current)) {
return optionItemRef.current;
Expand Down Expand Up @@ -123,6 +128,8 @@ function OptionRowLHNData({
movedToReport,
currentUserAccountID,
reportAttributesDerived,
policyTags,
login,
]);

return (
Expand Down
7 changes: 7 additions & 0 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
Card,
PersonalDetails,
PersonalDetailsList,
PolicyTagLists,
ReportActions,
ReportAttributesDerivedValue,
ReportNameValuePairs,
Expand Down Expand Up @@ -672,6 +673,8 @@ function getOptionData({
currentUserAccountID,
visibleReportActionsData,
reportAttributesDerived,
policyTags,
currentUserLogin,
}: {
report: OnyxEntry<Report>;
oneTransactionThreadReport: OnyxEntry<Report>;
Expand All @@ -694,6 +697,8 @@ function getOptionData({
currentUserAccountID: number;
visibleReportActionsData?: VisibleReportActionsDerivedValue;
reportAttributesDerived?: ReportAttributesDerivedValue['reports'];
policyTags?: OnyxEntry<PolicyTagLists>;
currentUserLogin?: string;
}): OptionData | undefined {
// When a user signs out, Onyx is cleared. Due to the lazy rendering with a virtual list, it's possible for
// this method to be called after the Onyx data has been cleared out. In that case, it's fine to do
Expand Down Expand Up @@ -834,6 +839,8 @@ function getOptionData({
isReportArchived,
reportMetadata,
reportAttributesDerived,
policyTags,
currentUserLogin,
lastAction,
});
}
Expand Down
Loading