diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index f29a4d85fc56..a209cb678382 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -502,6 +502,14 @@ function ReportScreen({route, navigation}: ReportScreenProps) { // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, [route, isLinkedMessagePageReady, reportActionIDFromRoute]); + const prevReportActions = usePrevious(reportActions); + useEffect(() => { + if (prevReportActions.length !== 0 || reportActions.length === 0) { + return; + } + fetchReport(); + }, [prevReportActions, reportActions, fetchReport]); + // If a user has chosen to leave a thread, and then returns to it (e.g. with the back button), we need to call `openReport` again in order to allow the user to rejoin and to receive real-time updates useEffect(() => { if (!shouldUseNarrowLayout || !isFocused || prevIsFocused || !isChatThread(report) || !isHiddenForCurrentUser(report) || isSingleTransactionView) { diff --git a/tests/ui/PaginationTest.tsx b/tests/ui/PaginationTest.tsx index 73df63153b1d..b8ee899e4c17 100644 --- a/tests/ui/PaginationTest.tsx +++ b/tests/ui/PaginationTest.tsx @@ -281,7 +281,7 @@ describe('Pagination', () => { await navigateToSidebarOption(REPORT_ID); expect(getReportActions()).toHaveLength(5); - TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 1); + TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 2); TestHelper.expectAPICommandToHaveBeenCalledWith('OpenReport', 0, {reportID: REPORT_ID}); TestHelper.expectAPICommandToHaveBeenCalled('GetOlderActions', 0); TestHelper.expectAPICommandToHaveBeenCalled('GetNewerActions', 0); @@ -292,7 +292,7 @@ describe('Pagination', () => { scrollToOffset(0); await waitForBatchedUpdatesWithAct(); - TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 1); + TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 2); TestHelper.expectAPICommandToHaveBeenCalled('GetOlderActions', 0); TestHelper.expectAPICommandToHaveBeenCalled('GetNewerActions', 0); }); @@ -305,7 +305,7 @@ describe('Pagination', () => { await navigateToSidebarOption(REPORT_ID); expect(getReportActions()).toHaveLength(CONST.REPORT.MIN_INITIAL_REPORT_ACTION_COUNT); - TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 1); + TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 2); TestHelper.expectAPICommandToHaveBeenCalledWith('OpenReport', 0, {reportID: REPORT_ID}); TestHelper.expectAPICommandToHaveBeenCalled('GetOlderActions', 0); TestHelper.expectAPICommandToHaveBeenCalled('GetNewerActions', 0); @@ -314,7 +314,7 @@ describe('Pagination', () => { scrollToOffset(LIST_CONTENT_SIZE.height); await waitForBatchedUpdatesWithAct(); - TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 1); + TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 2); TestHelper.expectAPICommandToHaveBeenCalled('GetOlderActions', 1); TestHelper.expectAPICommandToHaveBeenCalledWith('GetOlderActions', 0, {reportID: REPORT_ID, reportActionID: '4'}); TestHelper.expectAPICommandToHaveBeenCalled('GetNewerActions', 0); @@ -346,7 +346,7 @@ describe('Pagination', () => { expect(getReportActions()).toHaveLength(10); // There is 1 extra call here because of the comment linking report. - TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 3); + TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 4); TestHelper.expectAPICommandToHaveBeenCalledWith('OpenReport', 1, {reportID: REPORT_ID, reportActionID: '5'}); TestHelper.expectAPICommandToHaveBeenCalled('GetOlderActions', 0); TestHelper.expectAPICommandToHaveBeenCalledWith('GetNewerActions', 0, {reportID: REPORT_ID, reportActionID: '5'}); @@ -357,7 +357,7 @@ describe('Pagination', () => { scrollToOffset(0); await waitForBatchedUpdatesWithAct(); - TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 3); + TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 4); TestHelper.expectAPICommandToHaveBeenCalled('GetOlderActions', 0); TestHelper.expectAPICommandToHaveBeenCalled('GetNewerActions', 1); @@ -372,7 +372,7 @@ describe('Pagination', () => { scrollToOffset(0); await waitForBatchedUpdatesWithAct(); - TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 3); + TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 4); TestHelper.expectAPICommandToHaveBeenCalled('GetOlderActions', 0); TestHelper.expectAPICommandToHaveBeenCalled('GetNewerActions', 1);