From e781b278db029cbcb89d172e3c22d3fffd8cf9a2 Mon Sep 17 00:00:00 2001 From: dmkt9 Date: Wed, 17 Dec 2025 21:39:38 +0700 Subject: [PATCH 1/4] Fix - Empty report is shown briefly after adding a message and disappeared in Reports --- src/libs/actions/Report.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 0be98707ea04..672d1b7f7e98 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2971,6 +2971,20 @@ function buildNewReportOptimisticData( }, }); } + if (currentSearchQueryJSON?.type === CONST.SEARCH.DATA_TYPES.CHAT) { + // @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830 + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${currentSearchQueryJSON.hash}` as const, + value: { + data: { + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport?.reportID}`]: {[reportPreviewReportActionID]: {...optimisticReportPreview, reportID: parentReport?.reportID}}, + [`${ONYXKEYS.COLLECTION.REPORT}${parentReport?.reportID}`]: parentReport, + [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]: optimisticReportData, + }, + }, + }); + } const failureData: OnyxUpdate[] = [ { From 393187253f93f27f3a044f2e5731ff7ac5769a99 Mon Sep 17 00:00:00 2001 From: dmkt9 Date: Wed, 17 Dec 2025 22:57:11 +0700 Subject: [PATCH 2/4] Fix - Empty report is shown briefly after adding a message and disappeared in Reports --- tests/actions/ReportTest.ts | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 2e8f0aae252f..b5aa488efd34 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -7,6 +7,7 @@ import type {Mock} from 'jest-mock'; import Onyx from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import OnyxUtils from 'react-native-onyx/dist/OnyxUtils'; +import type {SearchQueryJSON} from '@components/Search/types'; import useAncestors from '@hooks/useAncestors'; import {getOnboardingMessages} from '@libs/actions/Welcome/OnboardingFlow'; import {WRITE_COMMANDS} from '@libs/API/types'; @@ -1890,6 +1891,51 @@ describe('actions/Report', () => { }); }); + it('should add the report preview action to the chat snapshot when it is created', async () => { + jest.spyOn(require('@src/libs/SearchQueryUtils'), 'getCurrentSearchQueryJSON').mockImplementationOnce( + () => + ({ + hash: currentHash, + query: 'test', + type: CONST.SEARCH.DATA_TYPES.CHAT, + status: '', + flatFilters: [], + }) as unknown as SearchQueryJSON, + ); + const accountID = 1234; + const policyID = '5678'; + + const policy = { + ...createRandomPolicy(Number(policyID)), + isPolicyExpenseChatEnabled: true, + type: CONST.POLICY.TYPE.TEAM, + autoReporting: false, + autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.IMMEDIATE, + harvesting: { + enabled: false, + }, + }; + await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); + + const {reportID} = Report.createNewReport({accountID}, true, false, policyID); + const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID); + + await waitForBatchedUpdates(); + + await new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${currentHash}`, + callback: (snapshot) => { + Onyx.disconnect(connection); + expect(snapshot?.data?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport?.reportID}`]).toBeTruthy(); + expect(snapshot?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReport?.reportID}`]).toBeTruthy(); + expect(snapshot?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]).toBeTruthy(); + resolve(null); + }, + }); + }); + }); + describe('completeOnboarding', () => { const TEST_USER_LOGIN = 'test@gmail.com'; const TEST_USER_ACCOUNT_ID = 1; From 3429ecbc085c6f6015322ad76b59e782caab1e30 Mon Sep 17 00:00:00 2001 From: dmkt9 Date: Mon, 5 Jan 2026 10:46:31 +0700 Subject: [PATCH 3/4] Fix - Empty report is shown briefly after adding a message and disappeared in Reports --- src/libs/actions/Report.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 26967cd3e947..6d8b2b6c4f51 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2996,8 +2996,7 @@ function buildNewReportOptimisticData( data: {[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]: optimisticReportData}, }, }); - } - if (currentSearchQueryJSON?.type === CONST.SEARCH.DATA_TYPES.CHAT) { + } else if (currentSearchQueryJSON?.type === CONST.SEARCH.DATA_TYPES.CHAT) { // @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830 optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, From 348b8e964e38e5a62750a54638f84ead2bb82dd3 Mon Sep 17 00:00:00 2001 From: dmkt9 Date: Mon, 5 Jan 2026 11:46:13 +0700 Subject: [PATCH 4/4] fix test --- tests/actions/ReportTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 7438b8faea93..14b30d8042b1 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -1917,7 +1917,7 @@ describe('actions/Report', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); - const {reportID} = Report.createNewReport({accountID}, true, false, policyID); + const {reportID} = Report.createNewReport({accountID}, true, false, policy); const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID); await waitForBatchedUpdates();