diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7b226b2e5c8e..fa365867044b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7218,7 +7218,7 @@ function shouldDisableThread(reportAction: OnyxInputOrEntry, repor ); } -function getAllAncestorReportActions(report: Report | null | undefined): Ancestor[] { +function getAllAncestorReportActions(report: Report | null | undefined, currentUpdatedReport?: OnyxEntry): Ancestor[] { if (!report) { return []; } @@ -7227,7 +7227,7 @@ function getAllAncestorReportActions(report: Report | null | undefined): Ancesto let parentReportActionID = report.parentReportActionID; while (parentReportID) { - const parentReport = getReportOrDraftReport(parentReportID); + const parentReport = currentUpdatedReport && currentUpdatedReport.reportID === parentReportID ? currentUpdatedReport : getReportOrDraftReport(parentReportID); const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, parentReportActionID ?? '-1'); if ( diff --git a/src/pages/home/report/ReportActionItemParentAction.tsx b/src/pages/home/report/ReportActionItemParentAction.tsx index ff7e9d4d7027..d3842786b162 100644 --- a/src/pages/home/report/ReportActionItemParentAction.tsx +++ b/src/pages/home/report/ReportActionItemParentAction.tsx @@ -77,7 +77,11 @@ function ReportActionItemParentAction({ key: `${ONYXKEYS.COLLECTION.REPORT}${ancestorReportID}`, callback: (val) => { ancestorReports.current[ancestorReportID] = val; - setAllAncestors(ReportUtils.getAllAncestorReportActions(report)); + // getAllAncestorReportActions use getReportOrDraftReport to get parent reports which gets the report from allReports that + // holds the report collection. However, allReports is not updated by the time this current callback is called. + // Therefore we need to pass the up-to-date report to getAllAncestorReportActions so that it uses the up-to-date report value + // to calculate, for instance, unread marker. + setAllAncestors(ReportUtils.getAllAncestorReportActions(report, val)); }, }), );