@@ -124,11 +124,11 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
124
124
const { shouldUseNarrowLayout, isSmallScreenWidth} = useResponsiveLayout ( ) ;
125
125
const route = useRoute ( ) ;
126
126
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
127
- const [ chatReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ moneyRequestReport ?. chatReportID || CONST . DEFAULT_NUMBER_ID } ` ) ;
127
+ const [ chatReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ moneyRequestReport ?. chatReportID } ` , { canBeMissing : true } ) ;
128
128
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
129
- const [ nextStep ] = useOnyx ( `${ ONYXKEYS . COLLECTION . NEXT_STEP } ${ moneyRequestReport ?. reportID || CONST . DEFAULT_NUMBER_ID } ` ) ;
130
- const [ transactionThreadReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ transactionThreadReportID } ` ) ;
131
- const [ session ] = useOnyx ( ONYXKEYS . SESSION ) ;
129
+ const [ nextStep ] = useOnyx ( `${ ONYXKEYS . COLLECTION . NEXT_STEP } ${ moneyRequestReport ?. reportID } ` , { canBeMissing : true } ) ;
130
+ const [ transactionThreadReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ transactionThreadReportID } ` , { canBeMissing : true } ) ;
131
+ const [ session ] = useOnyx ( ONYXKEYS . SESSION , { canBeMissing : true } ) ;
132
132
const requestParentReportAction = useMemo ( ( ) => {
133
133
if ( ! reportActions || ! transactionThreadReport ?. parentReportActionID ) {
134
134
return null ;
@@ -138,9 +138,12 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
138
138
const [ transactions ] = useOnyx ( ONYXKEYS . COLLECTION . TRANSACTION , {
139
139
selector : ( _transactions ) => reportTransactionsSelector ( _transactions , moneyRequestReport ?. reportID ) ,
140
140
initialValue : [ ] ,
141
+ canBeMissing : true ,
141
142
} ) ;
142
- const [ transaction ] = useOnyx ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ isMoneyRequestAction ( requestParentReportAction ) && getOriginalMessage ( requestParentReportAction ) ?. IOUTransactionID } ` ) ;
143
- const [ dismissedHoldUseExplanation , dismissedHoldUseExplanationResult ] = useOnyx ( ONYXKEYS . NVP_DISMISSED_HOLD_USE_EXPLANATION , { initialValue : true } ) ;
143
+ const [ transaction ] = useOnyx ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ isMoneyRequestAction ( requestParentReportAction ) && getOriginalMessage ( requestParentReportAction ) ?. IOUTransactionID } ` , {
144
+ canBeMissing : true ,
145
+ } ) ;
146
+ const [ dismissedHoldUseExplanation , dismissedHoldUseExplanationResult ] = useOnyx ( ONYXKEYS . NVP_DISMISSED_HOLD_USE_EXPLANATION , { initialValue : true , canBeMissing : true } ) ;
144
147
const isLoadingHoldUseExplained = isLoadingOnyxValue ( dismissedHoldUseExplanationResult ) ;
145
148
146
149
const { isPaidAnimationRunning, isApprovedAnimationRunning, stopAnimation, startAnimation, startApprovedAnimation} = usePaymentAnimations ( ) ;
@@ -170,7 +173,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
170
173
return ! ! transactions && transactions . length > 0 && transactions . every ( ( t ) => isExpensifyCardTransaction ( t ) && isPending ( t ) ) ;
171
174
} , [ transactions ] ) ;
172
175
const transactionIDs = useMemo ( ( ) => transactions ?. map ( ( t ) => t . transactionID ) ?? [ ] , [ transactions ] ) ;
173
- const [ allViolations ] = useOnyx ( ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS ) ;
176
+ const [ allViolations ] = useOnyx ( ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS , { canBeMissing : true } ) ;
174
177
const violations = useMemo (
175
178
( ) => Object . fromEntries ( Object . entries ( allViolations ?? { } ) . filter ( ( [ key ] ) => transactionIDs . includes ( key . replace ( ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS , '' ) ) ) ) ,
176
179
[ allViolations , transactionIDs ] ,
@@ -182,7 +185,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
182
185
const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils ( moneyRequestReport ?. reportID ) ;
183
186
const isPayAtEndExpense = isPayAtEndExpenseTransactionUtils ( transaction ) ;
184
187
const isArchivedReport = isArchivedReportWithID ( moneyRequestReport ?. reportID ) ;
185
- const [ archiveReason ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ moneyRequestReport ?. reportID } ` , { selector : getArchiveReason } ) ;
188
+ const [ archiveReason ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ moneyRequestReport ?. reportID } ` , { selector : getArchiveReason , canBeMissing : true } ) ;
186
189
187
190
const getCanIOUBePaid = useCallback (
188
191
( onlyShowPayElsewhere = false , shouldCheckApprovedState = true ) =>
@@ -288,7 +291,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
288
291
return options ;
289
292
} , [ moneyRequestReport , reportActions , selectedTransactionsID , session ?. accountID , setSelectedTransactionsID , translate ] ) ;
290
293
291
- const shouldShowSelectedTransactionsButton = ! ! selectedTransactionsOptions . length ;
294
+ const shouldShowSelectedTransactionsButton = ! ! selectedTransactionsOptions . length && ! transactionThreadReportID ;
292
295
293
296
const canIOUBePaid = useMemo ( ( ) => getCanIOUBePaid ( ) , [ getCanIOUBePaid ] ) ;
294
297
const canIOUBePaidAndApproved = useMemo ( ( ) => getCanIOUBePaid ( false , false ) , [ getCanIOUBePaid ] ) ;
@@ -353,7 +356,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
353
356
const isMoreContentShown = shouldShowNextStep || shouldShowStatusBar || ( shouldShowAnyButton && shouldUseNarrowLayout ) ;
354
357
const { isDelegateAccessRestricted} = useDelegateUserDetails ( ) ;
355
358
const [ isNoDelegateAccessMenuVisible , setIsNoDelegateAccessMenuVisible ] = useState ( false ) ;
356
- const [ isLoadingReportData ] = useOnyx ( ONYXKEYS . IS_LOADING_REPORT_DATA ) ;
359
+ const [ isLoadingReportData ] = useOnyx ( ONYXKEYS . IS_LOADING_REPORT_DATA , { canBeMissing : true } ) ;
357
360
358
361
const isReportInRHP = route . name === SCREENS . SEARCH . REPORT_RHP ;
359
362
const shouldDisplaySearchRouter = ! isReportInRHP || isSmallScreenWidth ;
@@ -497,6 +500,16 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
497
500
setIsDeleteRequestModalVisible ( false ) ;
498
501
} , [ canDeleteRequest ] ) ;
499
502
503
+ useEffect ( ( ) => {
504
+ if ( ! transactionThreadReportID ) {
505
+ return ;
506
+ }
507
+ setSelectedTransactionsID ( [ ] ) ;
508
+ // We don't need to run the effect on change of setSelectedTransactionsID since it can cause the infinite loop.
509
+ // eslint-disable-next-line react-compiler/react-compiler
510
+ // eslint-disable-next-line react-hooks/exhaustive-deps
511
+ } , [ transactionThreadReportID ] ) ;
512
+
500
513
const shouldShowBackButton = shouldDisplayBackButton || shouldUseNarrowLayout ;
501
514
502
515
return (
0 commit comments