Skip to content

Commit 04414ea

Browse files
authored
Merge pull request Expensify#64651 from callstack-internal/fix-freezing-app-v1
Fix freezing app
2 parents 573e824 + f73e5e0 commit 04414ea

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/libs/actions/OnyxDerived/configs/reportAttributes.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import ONYXKEYS from '@src/ONYXKEYS';
77
import type {ReportAttributesDerivedValue} from '@src/types/onyx';
88

99
let isFullyComputed = false;
10-
let recentlyUpdated: string[] = [];
1110

1211
const prepareReportKeys = (keys: string[]) => {
1312
return [
@@ -48,7 +47,7 @@ export default createOnyxDerivedValueConfig({
4847
}
4948
// if any of those keys changed, reset the isFullyComputed flag to recompute all reports
5049
// we need to recompute all report attributes on locale change because the report names are locale dependent
51-
if (hasKeyTriggeredCompute(ONYXKEYS.NVP_PREFERRED_LOCALE, sourceValues)) {
50+
if (hasKeyTriggeredCompute(ONYXKEYS.NVP_PREFERRED_LOCALE, sourceValues) || hasKeyTriggeredCompute(ONYXKEYS.PERSONAL_DETAILS_LIST, sourceValues)) {
5251
isFullyComputed = false;
5352
}
5453

@@ -89,16 +88,31 @@ export default createOnyxDerivedValueConfig({
8988
// if there are report-related updates, iterate over the updates
9089
if (updates.length > 0) {
9190
dataToIterate = prepareReportKeys(updates);
92-
recentlyUpdated = updates;
9391
} else if (!!transactionsUpdates || !!transactionViolationsUpdates) {
9492
let transactionReportIDs: string[] = [];
9593
if (transactionsUpdates) {
9694
transactionReportIDs = Object.values(transactionsUpdates).map((transaction) => `${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`);
9795
}
98-
// if transactions are updated, they might not be directly related to the reports yet (e.g. transaction is optimistically created)
99-
// so we use report keys that were updated before to recompute the reports
100-
const recentReportKeys = prepareReportKeys([...recentlyUpdated, ...transactionReportIDs]);
101-
dataToIterate = recentReportKeys;
96+
// Also handle transaction violations updates by extracting transaction IDs and finding their reports
97+
if (transactionViolationsUpdates) {
98+
const violationTransactionIDs = Object.keys(transactionViolationsUpdates).map((key) => key.replace(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, ''));
99+
const violationReportIDs = violationTransactionIDs
100+
.map((transactionID) => transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]?.reportID)
101+
.filter(Boolean)
102+
.map((reportID) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
103+
104+
// Also include chat reports for expense reports that have violations
105+
const chatReportIDs = violationReportIDs
106+
.map((reportKey) => reports?.[reportKey]?.chatReportID)
107+
.filter(Boolean)
108+
.map((chatReportID) => `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`);
109+
110+
transactionReportIDs = [...transactionReportIDs, ...violationReportIDs, ...chatReportIDs];
111+
}
112+
dataToIterate = prepareReportKeys(transactionReportIDs);
113+
} else {
114+
// No updates to process, return current value to prevent unnecessary computation
115+
return currentValue ?? {reports: {}, locale: null};
102116
}
103117
}
104118
const reportAttributes = dataToIterate.reduce<ReportAttributesDerivedValue['reports']>((acc, key) => {

tests/ui/LHNItemsPresence.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ describe('SidebarLinksData', () => {
232232
...createReport(false, undefined, undefined, undefined, TEST_POLICY_ID),
233233
ownerAccountID: TEST_USER_ACCOUNT_ID,
234234
type: CONST.REPORT.TYPE.EXPENSE,
235+
chatReportID: report.reportID,
235236
};
236237
const transaction = LHNTestUtils.getFakeTransaction(expenseReport.reportID);
237238
const transactionViolation = createFakeTransactionViolation();

0 commit comments

Comments
 (0)