diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index 0ff89bfa98c8..0d4714796921 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -1334,11 +1334,9 @@ function openReport(params: OpenReportActionParams) { // TODO: allPersonalDetails fallback should be removed in follow-up PRs https://github.com/Expensify/App/issues/73656 const participantAccountIDList = participants.map((p) => p.accountID).filter((id): id is number => id !== undefined); - const optimisticReport = reportActionsExist(reportID) - ? {} - : { - reportName: allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.reportName ?? CONST.REPORT.DEFAULT_REPORT_NAME, - }; + const existingReportName = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.reportName; + const isCreatingNewReport = !isEmptyObject(newReportObject); + const optimisticReport: Partial> = reportActionsExist(reportID) || !existingReportName ? {} : {reportName: existingReportName}; const optimisticData: Array< OnyxUpdate< @@ -1367,8 +1365,10 @@ function openReport(params: OpenReportActionParams) { }, ]; - // Only add the report update if optimisticReport has data - if (Object.keys(optimisticReport).length > 0) { + // We need a report update for both: + // 1) existing reports with a known name, and + // 2) new reports, because the new-report flow mutates optimisticData.at(0) into a SET on REPORT_. + if (isCreatingNewReport || Object.keys(optimisticReport).length > 0) { optimisticData.unshift({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, @@ -1568,7 +1568,6 @@ function openReport(params: OpenReportActionParams) { } // If we are creating a new report, we need to add the optimistic report data and a report action - const isCreatingNewReport = !isEmptyObject(newReportObject); if (isCreatingNewReport) { // Change the method to set for new reports because it doesn't exist yet, is faster, // and we need the data to be available when we navigate to the chat page