Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Comment on lines +507 to +509
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use OR condition here, fetchReport will be constantly called when reportActions changes, meanwhile we only want to fix the case when user was first invited to the room. This code looks different compared to the proposal that you proposed. Is there any reason for that?

Copy link
Copy Markdown
Contributor Author

@daledah daledah Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the proposal I used direct condition, where if prevReportActions.length === 0 && reportActions.length > 0 then we call fetchReport. In the PR, I use inverse condition to early return as it is our codebase convention.

If we use OR condition here, fetchReport will be constantly called when reportActions changes

I don't think this change creates this behavior, because we return everytime prevReportActions have lengh. Can you check again please?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty. I don't know why I read it as prevReportActions.length == 0 at first 😳

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) {
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/PaginationTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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'});
Expand All @@ -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);

Expand All @@ -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);

Expand Down