@@ -7,7 +7,6 @@ import ONYXKEYS from '@src/ONYXKEYS';
77import type { ReportAttributesDerivedValue } from '@src/types/onyx' ;
88
99let isFullyComputed = false ;
10- let recentlyUpdated : string [ ] = [ ] ;
1110
1211const 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 ) => {
0 commit comments