diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx index 690931ac19f80..a941184f214e7 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx @@ -288,6 +288,12 @@ function MoneyRequestReportTransactionList({ if (focusedRoute?.name !== SCREENS.RIGHT_MODAL.SEARCH_REPORT) { return; } + // Don't overwrite active transaction IDs when navigating from the duplicate review, + // as Review.tsx sets its own order via onPreviewPressed. + const backTo = (focusedRoute.params as Record | undefined)?.backTo; + if (backTo?.replaceAll(/\?.*/g, '').endsWith('/duplicates/review')) { + return; + } setActiveTransactionIDs(visualOrderTransactionIDs); }, [visualOrderTransactionIDs]); diff --git a/tests/unit/MoneyRequestReportTransactionListActiveTransactionIDsTest.tsx b/tests/unit/MoneyRequestReportTransactionListActiveTransactionIDsTest.tsx index cc41316738195..0ae287dfb67a2 100644 --- a/tests/unit/MoneyRequestReportTransactionListActiveTransactionIDsTest.tsx +++ b/tests/unit/MoneyRequestReportTransactionListActiveTransactionIDsTest.tsx @@ -34,6 +34,10 @@ function useActiveTransactionIDsEffect(visualOrderTransactionIDs: string[]) { if (focusedRoute?.name !== SCREENS.RIGHT_MODAL.SEARCH_REPORT) { return; } + const backTo = (focusedRoute.params as Record | undefined)?.backTo; + if (backTo?.replaceAll(/\?.*/g, '').endsWith('/duplicates/review')) { + return; + } setActiveTransactionIDs(visualOrderTransactionIDs); }, [visualOrderTransactionIDs]); @@ -173,6 +177,40 @@ describe('MoneyRequestReportTransactionList - Active Transaction IDs Effect', () expect(mockClearActiveTransactionIDs).not.toHaveBeenCalled(); }); + it('should NOT call setActiveTransactionIDs when backTo includes duplicates review', () => { + // Given the focused route is SEARCH_REPORT with backTo pointing to a duplicate review + mockFindFocusedRoute.mockReturnValue({ + name: SCREENS.RIGHT_MODAL.SEARCH_REPORT, + key: 'test-key', + params: {backTo: '/r/123/duplicates/review'}, + }); + + const transactionIDs = ['trans1', 'trans2']; + + // When the hook is rendered + renderHook(() => useActiveTransactionIDsEffect(transactionIDs)); + + // Then setActiveTransactionIDs should NOT be called because the IDs were already set by Review.tsx + expect(mockSetActiveTransactionIDs).not.toHaveBeenCalled(); + }); + + it('should NOT call setActiveTransactionIDs when backTo includes duplicates review with query params', () => { + // Given the focused route is SEARCH_REPORT with backTo including query params after duplicates/review + mockFindFocusedRoute.mockReturnValue({ + name: SCREENS.RIGHT_MODAL.SEARCH_REPORT, + key: 'test-key', + params: {backTo: '/r/456/duplicates/review?someParam=value'}, + }); + + const transactionIDs = ['trans1', 'trans2']; + + // When the hook is rendered + renderHook(() => useActiveTransactionIDsEffect(transactionIDs)); + + // Then setActiveTransactionIDs should NOT be called + expect(mockSetActiveTransactionIDs).not.toHaveBeenCalled(); + }); + it('should handle empty transaction IDs array', () => { // Given the focused route is SEARCH_REPORT mockFindFocusedRoute.mockReturnValue({name: SCREENS.RIGHT_MODAL.SEARCH_REPORT, key: 'test-key'});