From 3d40000d83f589c61f8c696b32f01a0e50137410 Mon Sep 17 00:00:00 2001 From: Faizan Shoukat Abbasi Date: Wed, 6 May 2026 01:39:42 +0500 Subject: [PATCH 1/4] 88162: Reports page - Custom report title briefly shows'Chat Report' when clicking a report row --- src/libs/actions/Report/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index 0ff89bfa98c8..4b0f55f70356 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -1334,11 +1334,8 @@ 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 optimisticReport: Partial> = reportActionsExist(reportID) || !existingReportName ? {} : {reportName: existingReportName}; const optimisticData: Array< OnyxUpdate< From f75df565e3c5e3a5368eda34af4095a60a14ea16 Mon Sep 17 00:00:00 2001 From: Faizan Shoukat Abbasi Date: Wed, 6 May 2026 02:54:05 +0500 Subject: [PATCH 2/4] updated the logic to always insert a report optimistic entry when isCreatingNewReport is true --- src/libs/actions/Report/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index 4b0f55f70356..0d4714796921 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -1335,6 +1335,7 @@ function openReport(params: OpenReportActionParams) { const participantAccountIDList = participants.map((p) => p.accountID).filter((id): id is number => id !== undefined); const existingReportName = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.reportName; + const isCreatingNewReport = !isEmptyObject(newReportObject); const optimisticReport: Partial> = reportActionsExist(reportID) || !existingReportName ? {} : {reportName: existingReportName}; const optimisticData: Array< @@ -1364,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}`, @@ -1565,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 From 389575defa762d8c5920402cff87015ec77cff24 Mon Sep 17 00:00:00 2001 From: Faizan Shoukat Abbasi Date: Tue, 12 May 2026 22:24:42 +0500 Subject: [PATCH 3/4] Added test cases --- tests/actions/ReportTest.ts | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 722d9b9edf16..f3db450a1dc8 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -1159,6 +1159,56 @@ describe('actions/Report', () => { TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1); }); + it('should not optimistically inject default report name when report has no known name', async () => { + const REPORT_ID = 'openReport_noKnownName'; + + setHasRadio(false); + await waitForBatchedUpdates(); + + Report.openReport({ + reportID: REPORT_ID, + introSelected: undefined, + betas: undefined, + }); + await waitForBatchedUpdates(); + + const report = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`); + expect(report?.reportName).toBeUndefined(); + + setHasRadio(true); + await waitForBatchedUpdates(); + }); + + it('should keep optimistic new report write on report collection key', async () => { + const REPORT_ID = 'openReport_newReportOptimistic'; + + setHasRadio(false); + await waitForBatchedUpdates(); + + Report.openReport({ + reportID: REPORT_ID, + introSelected: undefined, + betas: undefined, + newReportObject: { + reportID: REPORT_ID, + }, + }); + await waitForBatchedUpdates(); + + const report = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`); + expect(report).toMatchObject({ + reportID: REPORT_ID, + reportName: CONST.REPORT.DEFAULT_REPORT_NAME, + }); + + const loadingState = await getOnyxValue(`${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${REPORT_ID}`); + expect(loadingState?.reportID).toBeUndefined(); + expect(loadingState?.reportName).toBeUndefined(); + + setHasRadio(true); + await waitForBatchedUpdates(); + }); + it('openReport legacy preview fallback stores action under correct Onyx key and preserves existing actions', async () => { global.fetch = TestHelper.getGlobalFetchMock(); From a3ee9320e0ae4ce3fa16852272ccc96d825a6462 Mon Sep 17 00:00:00 2001 From: Faizan Shoukat Abbasi Date: Tue, 12 May 2026 22:46:50 +0500 Subject: [PATCH 4/4] Fixed lint issues --- tests/actions/ReportTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index f3db450a1dc8..7ed79e3d459d 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -1202,8 +1202,8 @@ describe('actions/Report', () => { }); const loadingState = await getOnyxValue(`${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${REPORT_ID}`); - expect(loadingState?.reportID).toBeUndefined(); - expect(loadingState?.reportName).toBeUndefined(); + expect(loadingState).not.toHaveProperty('reportID'); + expect(loadingState).not.toHaveProperty('reportName'); setHasRadio(true); await waitForBatchedUpdates();