diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx index eae6578d39e9..76620958286c 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx @@ -257,7 +257,7 @@ function MoneyRequestReportActionsList({ }, []); useEffect(() => { - if (isUnread(report, transactionThreadReport) || (lastAction && isCurrentActionUnread(report, lastAction))) { + if (isUnread(report, transactionThreadReport) || (lastAction && isCurrentActionUnread(report, lastAction, visibleReportActions))) { // On desktop, when the notification center is displayed, isVisible will return false. // Currently, there's no programmatic way to dismiss the notification center panel. // To handle this, we use the 'referrer' parameter to check if the current navigation is triggered from a notification. @@ -330,7 +330,7 @@ function MoneyRequestReportActionsList({ // Scan through each visible report action until we find the appropriate action to show the unread marker for (let index = startIndex; index >= endIndex; index--) { const reportAction = visibleReportActions.at(index); - const nextAction = visibleReportActions.at(index - 1); + const nextAction = index > 0 ? visibleReportActions.at(index - 1) : undefined; const isEarliestReceivedOfflineMessage = index === earliestReceivedOfflineMessageIndex; const shouldDisplayNewMarker = diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 40d12e88f016..990ed1c9ac55 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1883,9 +1883,9 @@ function isReportActionUnread(reportAction: OnyxEntry, lastReadTim * Check whether the current report action of the report is unread or not * */ -function isCurrentActionUnread(report: OnyxEntry, reportAction: ReportAction): boolean { +function isCurrentActionUnread(report: OnyxEntry, reportAction: ReportAction, visibleReportActions?: ReportAction[]): boolean { const lastReadTime = report?.lastReadTime ?? ''; - const sortedReportActions = getSortedReportActions(Object.values(getAllReportActions(report?.reportID))); + const sortedReportActions = visibleReportActions ?? getSortedReportActions(Object.values(getAllReportActions(report?.reportID))); const currentActionIndex = sortedReportActions.findIndex((action) => action.reportActionID === reportAction.reportActionID); if (currentActionIndex === -1) { return false; diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 3328a0c5f4f7..38669bc03d64 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -365,8 +365,7 @@ function ReportActionsList({ if (report.reportID !== prevReportID) { return; } - - if (isUnread(report, transactionThreadReport) || (lastAction && isCurrentActionUnread(report, lastAction))) { + if (isUnread(report, transactionThreadReport) || (lastAction && isCurrentActionUnread(report, lastAction, sortedVisibleReportActions))) { // On desktop, when the notification center is displayed, isVisible will return false. // Currently, there's no programmatic way to dismiss the notification center panel. // To handle this, we use the 'referrer' parameter to check if the current navigation is triggered from a notification.