Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
752818e
feat: allow multiple loads in hook
chrispader Nov 26, 2025
78b9e08
fix: remove `reportActionID` param
chrispader Nov 26, 2025
82871aa
fix: remove param from test
chrispader Nov 26, 2025
d52a3db
fix: implement `isReportActionLoaded` function using set for better p…
chrispader Nov 26, 2025
f52664a
fix: remove check for concurrent API calls
chrispader Nov 26, 2025
ddbe111
update dep arrays
chrispader Nov 26, 2025
9281641
fix: add back promise-based duplicate request prevention logic
chrispader Dec 2, 2025
813340d
Merge branch 'main' into pr/76104
chrispader Dec 3, 2025
e94134c
fix: jest test failing expectedly
chrispader Dec 3, 2025
8e53c67
Merge branch 'main' into pr/76104
chrispader Dec 5, 2025
67ee491
Merge branch 'main' into pr/76104
chrispader Dec 9, 2025
ffd9815
Merge branch 'main' into pr/76104
chrispader Dec 18, 2025
550ed29
Merge branch 'main' into pr/76104
chrispader Jan 12, 2026
46f49fa
fix: firefox scroll issue
chrispader Jan 12, 2026
742e02e
Merge branch 'main' into pr/76104
chrispader Jan 30, 2026
9cc3ef0
fix: don't auto scroll to begin of chat on new messages
chrispader Jan 30, 2026
67ac0fa
Merge branch 'main' into pr/76104
chrispader Feb 6, 2026
dd36c52
Revert "fix: don't auto scroll to begin of chat on new messages"
chrispader Feb 6, 2026
f3ae0a7
Merge branch 'main' into pr/76104
chrispader Feb 17, 2026
41c2d90
fix: TS errors
chrispader Feb 17, 2026
6e82b8d
fix: scrolling to bottom when new message is posted
chrispader Feb 17, 2026
e79c8e8
Merge branch 'main' into pr/76104
chrispader Feb 18, 2026
84a4a02
fix: only navigate if not in RHP
chrispader Feb 18, 2026
89a6999
fix: make `GetOlderActions` and `GetNewerActions` requests with side …
chrispader Feb 18, 2026
9ab146d
Merge branch 'main' into pr/76104
chrispader Feb 20, 2026
1d563e7
fix: add back `useLastUnreadReportAction` `OpenReport` param
chrispader Feb 20, 2026
f5c6ad8
fix: ignore duplicate API requests
chrispader Feb 24, 2026
8953594
fix: change import
chrispader Feb 24, 2026
b30e256
Merge branch 'main' into pr/76104
chrispader Feb 24, 2026
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
52 changes: 20 additions & 32 deletions src/hooks/useLoadReportActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useIsFocused} from '@react-navigation/native';
import {useCallback, useMemo, useRef} from 'react';
import {useCallback, useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {getNewerActions, getOlderActions} from '@userActions/Report';
import CONST from '@src/CONST';
Expand All @@ -11,9 +11,6 @@ type UseLoadReportActionsArguments = {
/** The id of the current report */
Comment thread
chrispader marked this conversation as resolved.
Resolved
reportID: string;

/** The id of the reportAction (if specific action was linked to */
reportActionID?: string;

/** The list of reportActions linked to the current report */
reportActions: ReportAction[];

Expand All @@ -34,16 +31,14 @@ type UseLoadReportActionsArguments = {
* Provides reusable logic to get the functions for loading older/newer reportActions.
* Used in the report displaying components
*/
function useLoadReportActions({reportID, reportActionID, reportActions, allReportActionIDs, transactionThreadReport, hasOlderActions, hasNewerActions}: UseLoadReportActionsArguments) {
const didLoadOlderChats = useRef(false);
const didLoadNewerChats = useRef(false);

function useLoadReportActions({reportID, reportActions, allReportActionIDs, transactionThreadReport, hasOlderActions, hasNewerActions}: UseLoadReportActionsArguments) {
Comment thread
chrispader marked this conversation as resolved.
Resolved
Comment thread
chrispader marked this conversation as resolved.
Resolved
const {isOffline} = useNetwork();
const isFocused = useIsFocused();

const newestReportAction = useMemo(() => reportActions?.at(0), [reportActions]);
const oldestReportAction = useMemo(() => reportActions?.at(-1), [reportActions]);

const isTransactionThreadReport = !isEmptyObject(transactionThreadReport);

// Track oldest/newest actions per report in a single pass
const {currentReportOldest, currentReportNewest, transactionThreadOldest, transactionThreadNewest} = useMemo(() => {
let currentReportNewestAction = null;
Expand All @@ -66,7 +61,7 @@ function useLoadReportActions({reportID, reportActionID, reportActions, allRepor
}
// Oldest = last matching action we encounter
currentReportOldestAction = action;
} else if (!isEmptyObject(transactionThreadReport) && transactionThreadReport?.reportID === targetReportID) {
} else if (isTransactionThreadReport && transactionThreadReport?.reportID === targetReportID) {
// Same logic for transaction thread
if (!transactionThreadNewestAction) {
transactionThreadNewestAction = action;
Expand All @@ -81,7 +76,7 @@ function useLoadReportActions({reportID, reportActionID, reportActions, allRepor
transactionThreadOldest: transactionThreadOldestAction,
transactionThreadNewest: transactionThreadNewestAction,
};
}, [reportActions, allReportActionIDs, reportID, transactionThreadReport]);
}, [allReportActionIDs, isTransactionThreadReport, reportActions, reportID, transactionThreadReport?.reportID]);

/**
* Retrieves the next set of reportActions for the chat once we are nearing the end of what we are currently
Expand All @@ -99,55 +94,48 @@ function useLoadReportActions({reportID, reportActionID, reportActions, allRepor
return;
}

didLoadOlderChats.current = true;

if (!isEmptyObject(transactionThreadReport)) {
if (isTransactionThreadReport) {
getOlderActions(reportID, currentReportOldest?.reportActionID);
getOlderActions(transactionThreadReport.reportID, transactionThreadOldest?.reportActionID);
getOlderActions(transactionThreadReport?.reportID, transactionThreadOldest?.reportActionID);
} else {
getOlderActions(reportID, currentReportOldest?.reportActionID);
}
},
[isOffline, oldestReportAction, hasOlderActions, transactionThreadReport, reportID, currentReportOldest?.reportActionID, transactionThreadOldest?.reportActionID],
[
currentReportOldest?.reportActionID,
hasOlderActions,
isOffline,
isTransactionThreadReport,
oldestReportAction,
reportID,
transactionThreadOldest?.reportActionID,
transactionThreadReport?.reportID,
],
);

const loadNewerChats = useCallback(
(force = false) => {
if (
!force &&
(!reportActionID ||
!isFocused ||
(!isFocused ||
!newestReportAction ||
!hasNewerActions ||
isOffline ||
// If there was an error only try again once on initial mount. We should also still load
// more in case we have cached messages.
didLoadNewerChats.current ||
newestReportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)
) {
return;
}

didLoadNewerChats.current = true;

if (!isEmptyObject(transactionThreadReport)) {
getNewerActions(reportID, currentReportNewest?.reportActionID);
getNewerActions(transactionThreadReport.reportID, transactionThreadNewest?.reportActionID);
} else if (newestReportAction) {
getNewerActions(reportID, newestReportAction.reportActionID);
}
},
[
reportActionID,
isFocused,
newestReportAction,
hasNewerActions,
isOffline,
transactionThreadReport,
reportID,
currentReportNewest?.reportActionID,
transactionThreadNewest?.reportActionID,
],
[currentReportNewest?.reportActionID, hasNewerActions, isFocused, isOffline, newestReportAction, reportID, transactionThreadNewest?.reportActionID, transactionThreadReport],
);

return {
Expand Down
6 changes: 2 additions & 4 deletions src/libs/API/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,11 @@ function paginate<TRequestType extends ApiRequestType, TCommand extends CommandO

switch (type) {
case CONST.API_REQUEST_TYPE.WRITE:
processRequest(request, type);
return;
return processRequest(request, type);
case CONST.API_REQUEST_TYPE.MAKE_REQUEST_WITH_SIDE_EFFECTS:
return processRequest(request, type);
case CONST.API_REQUEST_TYPE.READ:
waitForWrites(command as ReadCommand).then(() => processRequest(request, type));
return;
return waitForWrites(command as ReadCommand).then(() => processRequest(request, type));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep read pagination promise pending until request completes

useLoadReportActions now uses the returned promise from getOlderActions/getNewerActions to hold isLoading* flags, but the READ branch here resolves as soon as processRequest() is called, not when the paginated response is received and merged. During onStartReached/onEndReached, that drops the loading guard while the prior fetch is still in flight, so repeated boundary events can dispatch duplicate GetNewerActions/GetOlderActions requests with the same cursor.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is correct. @rlinoz not sure what is "allowed" to be a request with side effect, but if we actually want to wait until the API has sent it's response for these requests, i suppose we can treat that as a side effect?

I don't think there's another way of actually awaiting the response. Wdyt?

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.

Yeah, I don't think there is another way of waiting on response. Can you start a thread about this in #expert-contributors so we can get some feedback, please?

default:
throw new Error('Unknown API request type');
}
Expand Down
1 change: 1 addition & 0 deletions src/libs/API/parameters/OpenReportParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type OpenReportParams = {
*/
moneyRequestPreviewReportActionID?: string;
includePartiallySetupBankAccounts?: boolean;
useLastUnreadReportAction?: boolean;
};

export default OpenReportParams;
7 changes: 4 additions & 3 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
/** @deprecated This value is deprecated and will be removed soon after migration. Use the email from useCurrentUserPersonalDetails hook instead. */
let deprecatedCurrentUserLogin: string | undefined;

Onyx.connect({

Check warning on line 317 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -328,7 +328,7 @@
},
});

Onyx.connect({

Check warning on line 331 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => (conciergeReportIDOnyxConnect = value),
});
Expand All @@ -336,7 +336,7 @@
// map of reportID to all reportActions for that report
const allReportActions: OnyxCollection<ReportActions> = {};

Onyx.connect({

Check warning on line 339 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
if (!key || !actions) {
Expand All @@ -348,7 +348,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 351 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -357,7 +357,7 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
Onyx.connect({

Check warning on line 360 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand All @@ -372,7 +372,7 @@
});

let onboarding: OnyxEntry<Onboarding>;
Onyx.connect({

Check warning on line 375 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ONBOARDING,
callback: (val) => {
if (Array.isArray(val)) {
Expand All @@ -383,7 +383,7 @@
});

let deprecatedIntroSelected: OnyxEntry<IntroSelected> = {};
Onyx.connect({

Check warning on line 386 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_INTRO_SELECTED,
callback: (val) => (deprecatedIntroSelected = val),
});
Expand Down Expand Up @@ -1201,6 +1201,7 @@
parentReportActionID,
transactionID: transaction?.transactionID,
includePartiallySetupBankAccounts: true,
useLastUnreadReportAction: true,
};

if (optimisticSelfDMReport) {
Expand Down Expand Up @@ -1789,7 +1790,7 @@
*/
function getOlderActions(reportID: string | undefined, reportActionID: string | undefined) {
if (!reportID || !reportActionID) {
return;
return Promise.resolve();
}

const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_METADATA>> = [
Expand Down Expand Up @@ -1829,7 +1830,7 @@
reportActionID,
};

API.paginate(
return API.paginate(
CONST.API_REQUEST_TYPE.READ,
READ_COMMANDS.GET_OLDER_ACTIONS,
parameters,
Expand Down Expand Up @@ -1887,7 +1888,7 @@
reportActionID,
};

API.paginate(
return API.paginate(
CONST.API_REQUEST_TYPE.READ,
READ_COMMANDS.GET_NEWER_ACTIONS,
parameters,
Expand Down
24 changes: 5 additions & 19 deletions src/pages/inbox/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import InvertedFlatList from '@components/InvertedFlatList';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import {AUTOSCROLL_TO_TOP_THRESHOLD} from '@hooks/useFlatListScrollKey';
import useIsAnonymousUser from '@hooks/useIsAnonymousUser';
import useLocalize from '@hooks/useLocalize';
import useNetworkWithOfflineStatus from '@hooks/useNetworkWithOfflineStatus';
Expand Down Expand Up @@ -346,13 +345,10 @@ function ReportActionsList({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [lastAction?.created]);

const lastActionIndex = lastAction?.reportActionID;
const reportActionSize = useRef(sortedVisibleReportActions.length);
const lastVisibleActionCreated = getReportLastVisibleActionCreated(report, transactionThreadReport);
const hasNewestReportAction = lastAction?.created === lastVisibleActionCreated || isReportPreviewAction(lastAction);
const hasNewestReportActionRef = useRef(hasNewestReportAction);
hasNewestReportActionRef.current = hasNewestReportAction;
const previousLastIndex = useRef(lastActionIndex);
const sortedVisibleReportActionsRef = useRef(sortedVisibleReportActions);

const {isFloatingMessageCounterVisible, setIsFloatingMessageCounterVisible, trackVerticalScrolling, onViewableItemsChanged} = useReportUnreadMessageScrollTracking({
Expand All @@ -370,20 +366,6 @@ function ReportActionsList({
},
});

useEffect(() => {
if (
scrollOffsetRef.current < AUTOSCROLL_TO_TOP_THRESHOLD &&
previousLastIndex.current !== lastActionIndex &&
reportActionSize.current !== sortedVisibleReportActions.length &&
hasNewestReportAction
) {
setIsFloatingMessageCounterVisible(false);
reportScrollManager.scrollToBottom();
}
previousLastIndex.current = lastActionIndex;
reportActionSize.current = sortedVisibleReportActions.length;
}, [lastActionIndex, sortedVisibleReportActions.length, reportScrollManager, hasNewestReportAction, linkedReportActionID, setIsFloatingMessageCounterVisible, scrollOffsetRef]);

useEffect(() => {
const shouldTriggerScroll = shouldFocusToTopOnMount && prevHasCreatedActionAdded && !hasCreatedActionAdded;
if (!shouldTriggerScroll) {
Expand Down Expand Up @@ -549,9 +531,13 @@ function ReportActionsList({
if (action?.reportActionID) {
setActionIdToHighlight(action.reportActionID);
}
} else {
} else if (Navigation.getReportRHPActiveRoute()) {
setIsFloatingMessageCounterVisible(false);
reportScrollManager.scrollToBottom();
} else {
Navigation.setNavigationActionToMicrotaskQueue(() => {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID));
});
Comment on lines +538 to +540

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve RHP context when handling own non-preview actions

For non-REPORT_PREVIEW actions, this callback now always navigates to the base report route. Because the guard above allows execution when a report RHP route is active, sending a normal comment while the side panel is open will navigate away from that RHP context instead of just scrolling, unexpectedly closing the panel.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Addressing this!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only navigating if the ReportActionsList is not part of a RHP screen

}

setIsScrollToBottomEnabled(true);
Expand Down
1 change: 0 additions & 1 deletion src/pages/inbox/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ function ReportActionsView({

const {loadOlderChats, loadNewerChats} = useLoadReportActions({
reportID,
reportActionID,
reportActions,
allReportActionIDs,
transactionThreadReport,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type ChatContentScrollViewPlatformStyles from './types';

const chatContentScrollViewPlatformStyles: ChatContentScrollViewPlatformStyles = {
overflow: 'hidden',
overflow: 'clip',
};

export default chatContentScrollViewPlatformStyles;
11 changes: 6 additions & 5 deletions tests/ui/PaginationTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ describe('Pagination', () => {
// Here we have 5 messages from the initial OpenReport and 5 from the initial GetNewerActions.
expect(getReportActions()).toHaveLength(10);

// Simulate the backend returning no new messages to simulate reaching the start of the chat.
mockGetNewerActions(0);

// There is 1 extra call here because of the comment linking report.
TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 3);
TestHelper.expectAPICommandToHaveBeenCalledWith('OpenReport', 1, {reportID: REPORT_ID, reportActionID: '5'});
Expand All @@ -390,22 +393,20 @@ describe('Pagination', () => {

TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 3);
TestHelper.expectAPICommandToHaveBeenCalled('GetOlderActions', 0);
TestHelper.expectAPICommandToHaveBeenCalled('GetNewerActions', 1);
TestHelper.expectAPICommandToHaveBeenCalled('GetNewerActions', 2);

// We now have 10 messages. 5 from the initial OpenReport and 5 from the GetNewerActions call.
expect(getReportActions()).toHaveLength(10);

// Simulate the backend returning no new messages to simulate reaching the start of the chat.
mockGetNewerActions(0);

scrollToOffset(500);
await waitForBatchedUpdatesWithAct();
scrollToOffset(0);
await waitForBatchedUpdatesWithAct();

// When there are no newer actions, we don't want to trigger GetNewerActions again.
TestHelper.expectAPICommandToHaveBeenCalled('OpenReport', 3);
TestHelper.expectAPICommandToHaveBeenCalled('GetOlderActions', 0);
TestHelper.expectAPICommandToHaveBeenCalled('GetNewerActions', 1);
TestHelper.expectAPICommandToHaveBeenCalled('GetNewerActions', 2);

// We still have 15 messages. 5 from the initial OpenReport and 5 from the GetNewerActions call.
expect(getReportActions()).toHaveLength(10);
Expand Down
1 change: 0 additions & 1 deletion tests/unit/useLoadReportActionsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ describe('useLoadReportActions', () => {
const props = {
...baseProps,
hasNewerActions: true,
reportActionID: 'EXISTING_ACTION_ID',
};

const {result} = renderHook(() => useLoadReportActions(props));
Expand Down
Loading