From 95a6f047b9eac49b737300c41565752b04ea5836 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Wed, 28 Aug 2024 18:51:47 +0300 Subject: [PATCH 1/2] fix unread marker bug in ReportActionItemParentAction --- src/libs/ReportUtils.ts | 4 ++-- src/pages/home/report/ReportActionItemParentAction.tsx | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a000d64a9adf..b45c958ff72e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7169,7 +7169,7 @@ function shouldDisableThread(reportAction: OnyxInputOrEntry, repor ); } -function getAllAncestorReportActions(report: Report | null | undefined): Ancestor[] { +function getAllAncestorReportActions(report: Report | null | undefined, ancestorReports?: Record>): Ancestor[] { if (!report) { return []; } @@ -7178,7 +7178,7 @@ function getAllAncestorReportActions(report: Report | null | undefined): Ancesto let parentReportActionID = report.parentReportActionID; while (parentReportID) { - const parentReport = getReportOrDraftReport(parentReportID); + const parentReport = ancestorReports?.[parentReportID] ?? 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 41943485f171..285c8e3e9ee4 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)); + // We pass ancestorReports to getAllAncestorReportActions because getReportOrDraftReport we use inside it + // to get parent reports will not get an up-to-date version of the report at this point in time. + // The reason is this callback is called earlier than the callback called to updated allReports in + // ReportConnection.getAllReports as it subscribes to the whole report collection with waitForCollectionCallback option. + setAllAncestors(ReportUtils.getAllAncestorReportActions(report, ancestorReports.current)); }, }), ); From 2a31807a892dfeac089acca204a3c8650866f12e Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Thu, 29 Aug 2024 00:20:07 +0300 Subject: [PATCH 2/2] pass val to getAllAncestorReportActions --- src/libs/ReportUtils.ts | 4 ++-- src/pages/home/report/ReportActionItemParentAction.tsx | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 136e63e58b11..f64f6c30fa5a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7174,7 +7174,7 @@ function shouldDisableThread(reportAction: OnyxInputOrEntry, repor ); } -function getAllAncestorReportActions(report: Report | null | undefined, ancestorReports?: Record>): Ancestor[] { +function getAllAncestorReportActions(report: Report | null | undefined, currentUpdatedReport?: OnyxEntry): Ancestor[] { if (!report) { return []; } @@ -7183,7 +7183,7 @@ function getAllAncestorReportActions(report: Report | null | undefined, ancestor let parentReportActionID = report.parentReportActionID; while (parentReportID) { - const parentReport = ancestorReports?.[parentReportID] ?? 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 285c8e3e9ee4..af73bab749a3 100644 --- a/src/pages/home/report/ReportActionItemParentAction.tsx +++ b/src/pages/home/report/ReportActionItemParentAction.tsx @@ -77,11 +77,11 @@ function ReportActionItemParentAction({ key: `${ONYXKEYS.COLLECTION.REPORT}${ancestorReportID}`, callback: (val) => { ancestorReports.current[ancestorReportID] = val; - // We pass ancestorReports to getAllAncestorReportActions because getReportOrDraftReport we use inside it - // to get parent reports will not get an up-to-date version of the report at this point in time. - // The reason is this callback is called earlier than the callback called to updated allReports in - // ReportConnection.getAllReports as it subscribes to the whole report collection with waitForCollectionCallback option. - setAllAncestors(ReportUtils.getAllAncestorReportActions(report, ancestorReports.current)); + // 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)); }, }), );