@@ -100,7 +100,8 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
100100 // report is guaranteed to exist — callers only render this component when report is loaded
101101 const [ report ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ reportIDFromRoute } ` ) as unknown as [ OnyxTypes . Report ] ;
102102 const [ policy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY } ${ getNonEmptyStringOnyxID ( report ?. policyID ) } ` ) ;
103- const [ reportMetadata ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_METADATA } ${ reportIDFromRoute } ` ) ;
103+ const [ reportLoadingState ] = useOnyx ( `${ ONYXKEYS . COLLECTION . RAM_ONLY_REPORT_LOADING_STATE } ${ reportIDFromRoute } ` ) ;
104+ const [ reportPaginationState ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_PAGINATION_STATE } ${ reportIDFromRoute } ` ) ;
104105 const reportID = report ?. reportID ;
105106
106107 const { reportActions : unfilteredReportActions , hasNewerActions, hasOlderActions} = usePaginatedReportActions ( reportID , route ?. params ?. reportActionID ) ;
@@ -116,8 +117,8 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
116117 ( ) => Object . values ( allReportTransactions ?? { } ) . some ( ( transaction ) => transaction ?. pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ) ,
117118 [ allReportTransactions ] ,
118119 ) ;
119- const newTransactions = useNewTransactions ( reportMetadata ?. hasOnceLoadedReportActions , reportTransactions ) ;
120- const showReportActionsLoadingState = reportMetadata ?. isLoadingInitialReportActions && ! reportMetadata ?. hasOnceLoadedReportActions ;
120+ const newTransactions = useNewTransactions ( reportLoadingState ?. hasOnceLoadedReportActions , reportTransactions ) ;
121+ const showReportActionsLoadingState = reportLoadingState ?. isLoadingInitialReportActions && ! reportLoadingState ?. hasOnceLoadedReportActions ;
121122 const reportTransactionIDs = useMemo ( ( ) => transactions . map ( ( transaction ) => transaction . transactionID ) , [ transactions ] ) ;
122123 const [ chatReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ getNonEmptyStringOnyxID ( report ?. chatReportID ) } ` ) ;
123124
@@ -225,23 +226,31 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
225226 transactionThreadReport,
226227 hasOlderActions,
227228 hasNewerActions,
228- newestFetchedReportActionID : reportMetadata ?. newestFetchedReportActionID ,
229+ newestFetchedReportActionID : reportPaginationState ?. newestFetchedReportActionID ,
229230 } ) ;
230231
231- const hasFinishedInitialLoad = reportMetadata ?. isLoadingInitialReportActions === false ;
232+ const hasFinishedInitialLoad = reportLoadingState ?. isLoadingInitialReportActions === false ;
232233 const prevNewestFetchedIDRef = useRef < string | undefined > ( undefined ) ;
233234 useEffect ( ( ) => {
234- if ( hasFinishedInitialLoad && hasNewerActions && reportActions . length > 0 && ! isOffline && ! reportMetadata ?. isLoadingNewerReportActions ) {
235+ if ( hasFinishedInitialLoad && hasNewerActions && reportActions . length > 0 && ! isOffline && ! reportLoadingState ?. isLoadingNewerReportActions ) {
235236 // Safety guard: if the cursor hasn't advanced since the last call, the server
236237 // isn't returning new data. Stop to prevent an infinite request loop.
237- const currentCursor = reportMetadata ?. newestFetchedReportActionID ;
238+ const currentCursor = reportPaginationState ?. newestFetchedReportActionID ;
238239 if ( prevNewestFetchedIDRef . current !== undefined && prevNewestFetchedIDRef . current === currentCursor ) {
239240 return ;
240241 }
241242 prevNewestFetchedIDRef . current = currentCursor ;
242243 loadNewerChats ( false ) ;
243244 }
244- } , [ hasFinishedInitialLoad , reportActions . length , hasNewerActions , isOffline , reportMetadata ?. isLoadingNewerReportActions , reportMetadata ?. newestFetchedReportActionID , loadNewerChats ] ) ;
245+ } , [
246+ hasFinishedInitialLoad ,
247+ reportActions . length ,
248+ hasNewerActions ,
249+ isOffline ,
250+ reportLoadingState ?. isLoadingNewerReportActions ,
251+ reportPaginationState ?. newestFetchedReportActionID ,
252+ loadNewerChats ,
253+ ] ) ;
245254
246255 // Backfill loop: the backend prioritizes IOU actions in OpenReport/GetNewerActions for money
247256 // request reports, which can leave non-IOU chat messages in a gap between the IOU-biased cursor
@@ -257,18 +266,18 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
257266 isBackfillingRef . current = false ;
258267 }
259268 useEffect ( ( ) => {
260- if ( ! hasFinishedInitialLoad || isOffline || hasNewerActions || reportMetadata ?. isLoadingNewerReportActions || reportMetadata ?. isLoadingOlderReportActions ) {
269+ if ( ! hasFinishedInitialLoad || isOffline || hasNewerActions || reportLoadingState ?. isLoadingNewerReportActions || reportLoadingState ?. isLoadingOlderReportActions ) {
261270 return ;
262271 }
263272
264273 if ( ! isBackfillingRef . current ) {
265274 const hasIOUActions = reportActions . some ( ( action ) => isMoneyRequestAction ( action ) ) ;
266- if ( ! hasIOUActions || reportActions . length < BACKFILL_MIN_ACTIONS_THRESHOLD || ! reportMetadata ?. newestFetchedReportActionID ) {
275+ if ( ! hasIOUActions || reportActions . length < BACKFILL_MIN_ACTIONS_THRESHOLD || ! reportPaginationState ?. newestFetchedReportActionID ) {
267276 return ;
268277 }
269278 }
270279
271- const cursor = isBackfillingRef . current ? reportMetadata ?. oldestFetchedReportActionID : reportMetadata ?. newestFetchedReportActionID ;
280+ const cursor = isBackfillingRef . current ? reportPaginationState ?. oldestFetchedReportActionID : reportPaginationState ?. newestFetchedReportActionID ;
272281 if ( ! cursor ) {
273282 return ;
274283 }
@@ -287,10 +296,10 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
287296 hasFinishedInitialLoad ,
288297 isOffline ,
289298 hasNewerActions ,
290- reportMetadata ?. isLoadingNewerReportActions ,
291- reportMetadata ?. isLoadingOlderReportActions ,
292- reportMetadata ?. newestFetchedReportActionID ,
293- reportMetadata ?. oldestFetchedReportActionID ,
299+ reportLoadingState ?. isLoadingNewerReportActions ,
300+ reportLoadingState ?. isLoadingOlderReportActions ,
301+ reportPaginationState ?. newestFetchedReportActionID ,
302+ reportPaginationState ?. oldestFetchedReportActionID ,
294303 reportActions ,
295304 reportID ,
296305 ] ) ;
@@ -357,7 +366,7 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
357366 // To handle this, we use the 'referrer' parameter to check if the current navigation is triggered from a notification.
358367 const isFromNotification = route ?. params ?. referrer === CONST . REFERRER . NOTIFICATION ;
359368 if ( ( isVisible || isFromNotification ) && scrollingVerticalBottomOffset . current < CONST . REPORT . ACTIONS . ACTION_VISIBLE_THRESHOLD ) {
360- readNewestAction ( report ?. reportID , ! ! reportMetadata ?. hasOnceLoadedReportActions ) ;
369+ readNewestAction ( report ?. reportID , ! ! reportLoadingState ?. hasOnceLoadedReportActions ) ;
361370 if ( isFromNotification ) {
362371 Navigation . setParams ( { referrer : undefined } ) ;
363372 }
@@ -366,7 +375,7 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
366375 }
367376 }
368377 // eslint-disable-next-line react-hooks/exhaustive-deps
369- } , [ report ?. lastVisibleActionCreated , transactionThreadReport ?. lastVisibleActionCreated , report ?. reportID , isVisible , reportMetadata ?. hasOnceLoadedReportActions ] ) ;
378+ } , [ report ?. lastVisibleActionCreated , transactionThreadReport ?. lastVisibleActionCreated , report ?. reportID , isVisible , reportLoadingState ?. hasOnceLoadedReportActions ] ) ;
370379
371380 useEffect ( ( ) => {
372381 if ( ! isVisible || ! isFocused ) {
@@ -390,15 +399,15 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
390399 return ;
391400 }
392401
393- readNewestAction ( report ?. reportID , ! ! reportMetadata ?. hasOnceLoadedReportActions ) ;
402+ readNewestAction ( report ?. reportID , ! ! reportLoadingState ?. hasOnceLoadedReportActions ) ;
394403 userActiveSince . current = DateUtils . getDBTime ( ) ;
395404
396405 // This effect logic to `mark as read` will only run when the report focused has new messages and the App visibility
397406 // is changed to visible(meaning user switched to app/web, while user was previously using different tab or application).
398407 // We will mark the report as read in the above case which marks the LHN report item as read while showing the new message
399408 // marker for the chat messages received while the user wasn't focused on the report or on another browser tab for web.
400409 // eslint-disable-next-line react-hooks/exhaustive-deps
401- } , [ isFocused , isVisible , reportMetadata ?. hasOnceLoadedReportActions ] ) ;
410+ } , [ isFocused , isVisible , reportLoadingState ?. hasOnceLoadedReportActions ] ) ;
402411
403412 /**
404413 * The index of the earliest message that was received while offline
@@ -448,7 +457,7 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
448457 // We additionally track the top offset to be able to scroll to the new transaction when it's added
449458 scrollingVerticalTopOffset . current = contentOffset . y ;
450459 } ,
451- hasOnceLoadedReportActions : ! ! reportMetadata ?. hasOnceLoadedReportActions ,
460+ hasOnceLoadedReportActions : ! ! reportLoadingState ?. hasOnceLoadedReportActions ,
452461 } ) ;
453462
454463 useScrollToEndOnNewMessageReceived ( {
@@ -620,8 +629,8 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
620629
621630 reportScrollManager . scrollToEnd ( ) ;
622631 readActionSkipped . current = false ;
623- readNewestAction ( report ?. reportID , ! ! reportMetadata ?. hasOnceLoadedReportActions ) ;
624- } , [ setIsFloatingMessageCounterVisible , hasNewestReportAction , reportScrollManager , report ?. reportID , reportMetadata ?. hasOnceLoadedReportActions , introSelected , betas ] ) ;
632+ readNewestAction ( report ?. reportID , ! ! reportLoadingState ?. hasOnceLoadedReportActions ) ;
633+ } , [ setIsFloatingMessageCounterVisible , hasNewestReportAction , reportScrollManager , report ?. reportID , reportLoadingState ?. hasOnceLoadedReportActions , introSelected , betas ] ) ;
625634
626635 const scrollToNewTransaction = useCallback (
627636 ( pageY : number ) => {
0 commit comments