From c8a404fe43847bb74421f9cf199f4dcab77f4f95 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Wed, 22 May 2024 15:22:09 +0200 Subject: [PATCH 1/6] feat: add specific api abort controller --- .../API/parameters/SearchForReportsParams.ts | 1 + src/libs/HttpUtils.ts | 22 +++++++++++++------ src/libs/actions/Report.ts | 2 +- src/pages/ChatFinderPage/index.tsx | 3 +++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/libs/API/parameters/SearchForReportsParams.ts b/src/libs/API/parameters/SearchForReportsParams.ts index b6d1bbadb1dc..5cc90e39ffed 100644 --- a/src/libs/API/parameters/SearchForReportsParams.ts +++ b/src/libs/API/parameters/SearchForReportsParams.ts @@ -1,5 +1,6 @@ type SearchForReportsParams = { searchInput: string; + canCancel?: boolean; }; export default SearchForReportsParams; diff --git a/src/libs/HttpUtils.ts b/src/libs/HttpUtils.ts index 842776d0c8dd..8184ea09e995 100644 --- a/src/libs/HttpUtils.ts +++ b/src/libs/HttpUtils.ts @@ -14,6 +14,8 @@ import HttpsError from './Errors/HttpsError'; let shouldFailAllRequests = false; let shouldForceOffline = false; +type AbortCommand = 'All' | 'SearchForReports'; + Onyx.connect({ key: ONYXKEYS.NETWORK, callback: (network) => { @@ -26,7 +28,9 @@ Onyx.connect({ }); // We use the AbortController API to terminate pending request in `cancelPendingRequests` -let cancellationController = new AbortController(); +const abortControllerMap = new Map(); +abortControllerMap.set('All', new AbortController()); +abortControllerMap.set('SearchForReports', new AbortController()); // Some existing old commands (6+ years) exempted from the auth writes count check const exemptedCommandsWithAuthWrites: string[] = ['SetWorkspaceAutoReportingFrequency']; @@ -45,11 +49,11 @@ const APICommandRegex = /\/api\/([^&?]+)\??.*/; * Send an HTTP request, and attempt to resolve the json response. * If there is a network error, we'll set the application offline. */ -function processHTTPRequest(url: string, method: RequestType = 'get', body: FormData | null = null, canCancel = true): Promise { +function processHTTPRequest(url: string, method: RequestType = 'get', body: FormData | null = null, abortSignal: AbortSignal | undefined = undefined): Promise { const startTime = new Date().valueOf(); return fetch(url, { // We hook requests to the same Controller signal, so we can cancel them all at once - signal: canCancel ? cancellationController.signal : undefined, + signal: abortSignal, method, body, }) @@ -159,15 +163,19 @@ function xhr(command: string, data: Record, type: RequestType = }); const url = ApiUtils.getCommandURL({shouldUseSecure, command}); - return processHTTPRequest(url, type, formData, Boolean(data.canCancel)); + + const abortSignalController = data.canCancel ? abortControllerMap.get(command as AbortCommand) ?? abortControllerMap.get('All') : undefined; + return processHTTPRequest(url, type, formData, abortSignalController?.signal); } -function cancelPendingRequests() { - cancellationController.abort(); +function cancelPendingRequests(command: AbortCommand = 'All') { + const controller = abortControllerMap.get(command) ?? abortControllerMap.get('All'); + + controller?.abort(); // We create a new instance because once `abort()` is called any future requests using the same controller would // automatically get rejected: https://dom.spec.whatwg.org/#abortcontroller-api-integration - cancellationController = new AbortController(); + abortControllerMap.set(command, new AbortController()); } export default { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 91a0ce5da930..39f7552b917e 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3546,7 +3546,7 @@ function searchForReports(searchInput: string, policyID?: string) { ]; const searchForRoomToMentionParams: SearchForRoomsToMentionParams = {query: searchInput, policyID: policyID ?? ''}; - const searchForReportsParams: SearchForReportsParams = {searchInput}; + const searchForReportsParams: SearchForReportsParams = {searchInput, canCancel: true}; API.read(policyID ? READ_COMMANDS.SEARCH_FOR_ROOMS_TO_MENTION : READ_COMMANDS.SEARCH_FOR_REPORTS, policyID ? searchForRoomToMentionParams : searchForReportsParams, { successData, diff --git a/src/pages/ChatFinderPage/index.tsx b/src/pages/ChatFinderPage/index.tsx index d4b856e6955e..4d0f6b8af3bf 100644 --- a/src/pages/ChatFinderPage/index.tsx +++ b/src/pages/ChatFinderPage/index.tsx @@ -12,6 +12,7 @@ import useDebouncedState from '@hooks/useDebouncedState'; import useDismissedReferralBanners from '@hooks/useDismissedReferralBanners'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; +import HttpUtils from '@libs/HttpUtils'; import type {MaybePhraseKey} from '@libs/Localize'; import Navigation from '@libs/Navigation/Navigation'; import type {RootStackParamList} from '@libs/Navigation/types'; @@ -143,6 +144,8 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa return; } + HttpUtils.cancelPendingRequests('SearchForReports'); + if (option.reportID) { setSearchValue(''); Navigation.dismissModal(option.reportID); From e61b980ffd35a5b4633e11ba84b599f5d1c03566 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Thu, 23 May 2024 13:40:19 +0200 Subject: [PATCH 2/6] refactor: use read_commands const --- src/libs/API/types.ts | 1 + src/libs/HttpUtils.ts | 12 ++++++------ src/pages/ChatFinderPage/index.tsx | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 08bc5eddd087..ae4d09e8c78d 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -480,6 +480,7 @@ const READ_COMMANDS = { OPEN_POLICY_MORE_FEATURES_PAGE: 'OpenPolicyMoreFeaturesPage', OPEN_POLICY_ACCOUNTING_PAGE: 'OpenPolicyAccountingPage', SEARCH: 'Search', + ALL: 'All', } as const; type ReadCommand = ValueOf; diff --git a/src/libs/HttpUtils.ts b/src/libs/HttpUtils.ts index 8184ea09e995..5559e0ae7dd7 100644 --- a/src/libs/HttpUtils.ts +++ b/src/libs/HttpUtils.ts @@ -7,14 +7,14 @@ import type {RequestType} from '@src/types/onyx/Request'; import type Response from '@src/types/onyx/Response'; import * as NetworkActions from './actions/Network'; import * as UpdateRequired from './actions/UpdateRequired'; -import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from './API/types'; +import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from './API/types'; import * as ApiUtils from './ApiUtils'; import HttpsError from './Errors/HttpsError'; let shouldFailAllRequests = false; let shouldForceOffline = false; -type AbortCommand = 'All' | 'SearchForReports'; +type AbortCommand = typeof READ_COMMANDS.ALL | typeof READ_COMMANDS.SEARCH_FOR_REPORTS; Onyx.connect({ key: ONYXKEYS.NETWORK, @@ -29,8 +29,8 @@ Onyx.connect({ // We use the AbortController API to terminate pending request in `cancelPendingRequests` const abortControllerMap = new Map(); -abortControllerMap.set('All', new AbortController()); -abortControllerMap.set('SearchForReports', new AbortController()); +abortControllerMap.set(READ_COMMANDS.ALL, new AbortController()); +abortControllerMap.set(READ_COMMANDS.SEARCH_FOR_REPORTS, new AbortController()); // Some existing old commands (6+ years) exempted from the auth writes count check const exemptedCommandsWithAuthWrites: string[] = ['SetWorkspaceAutoReportingFrequency']; @@ -168,8 +168,8 @@ function xhr(command: string, data: Record, type: RequestType = return processHTTPRequest(url, type, formData, abortSignalController?.signal); } -function cancelPendingRequests(command: AbortCommand = 'All') { - const controller = abortControllerMap.get(command) ?? abortControllerMap.get('All'); +function cancelPendingRequests(command: AbortCommand = READ_COMMANDS.ALL) { + const controller = abortControllerMap.get(command) ?? abortControllerMap.get(READ_COMMANDS.ALL); controller?.abort(); diff --git a/src/pages/ChatFinderPage/index.tsx b/src/pages/ChatFinderPage/index.tsx index 4d0f6b8af3bf..23972b8f0913 100644 --- a/src/pages/ChatFinderPage/index.tsx +++ b/src/pages/ChatFinderPage/index.tsx @@ -12,6 +12,7 @@ import useDebouncedState from '@hooks/useDebouncedState'; import useDismissedReferralBanners from '@hooks/useDismissedReferralBanners'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; +import {READ_COMMANDS} from '@libs/API/types'; import HttpUtils from '@libs/HttpUtils'; import type {MaybePhraseKey} from '@libs/Localize'; import Navigation from '@libs/Navigation/Navigation'; @@ -144,7 +145,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa return; } - HttpUtils.cancelPendingRequests('SearchForReports'); + HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); if (option.reportID) { setSearchValue(''); From e0b0ec66607d88382f1694ef583ad7d181de45b2 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Thu, 23 May 2024 13:58:16 +0200 Subject: [PATCH 3/6] fix: fix typescript --- src/libs/API/types.ts | 1 - src/libs/HttpUtils.ts | 17 +++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index ae4d09e8c78d..08bc5eddd087 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -480,7 +480,6 @@ const READ_COMMANDS = { OPEN_POLICY_MORE_FEATURES_PAGE: 'OpenPolicyMoreFeaturesPage', OPEN_POLICY_ACCOUNTING_PAGE: 'OpenPolicyAccountingPage', SEARCH: 'Search', - ALL: 'All', } as const; type ReadCommand = ValueOf; diff --git a/src/libs/HttpUtils.ts b/src/libs/HttpUtils.ts index 5559e0ae7dd7..a62efe86dd66 100644 --- a/src/libs/HttpUtils.ts +++ b/src/libs/HttpUtils.ts @@ -14,7 +14,12 @@ import HttpsError from './Errors/HttpsError'; let shouldFailAllRequests = false; let shouldForceOffline = false; -type AbortCommand = typeof READ_COMMANDS.ALL | typeof READ_COMMANDS.SEARCH_FOR_REPORTS; +const ABORT_COMMANDS = { + All: 'All', + SearchForReports: READ_COMMANDS.SEARCH_FOR_REPORTS, +} as const; + +type AbortCommand = (typeof ABORT_COMMANDS)[keyof typeof ABORT_COMMANDS]; Onyx.connect({ key: ONYXKEYS.NETWORK, @@ -29,8 +34,8 @@ Onyx.connect({ // We use the AbortController API to terminate pending request in `cancelPendingRequests` const abortControllerMap = new Map(); -abortControllerMap.set(READ_COMMANDS.ALL, new AbortController()); -abortControllerMap.set(READ_COMMANDS.SEARCH_FOR_REPORTS, new AbortController()); +abortControllerMap.set(ABORT_COMMANDS.All, new AbortController()); +abortControllerMap.set(ABORT_COMMANDS.SearchForReports, new AbortController()); // Some existing old commands (6+ years) exempted from the auth writes count check const exemptedCommandsWithAuthWrites: string[] = ['SetWorkspaceAutoReportingFrequency']; @@ -164,12 +169,12 @@ function xhr(command: string, data: Record, type: RequestType = const url = ApiUtils.getCommandURL({shouldUseSecure, command}); - const abortSignalController = data.canCancel ? abortControllerMap.get(command as AbortCommand) ?? abortControllerMap.get('All') : undefined; + const abortSignalController = data.canCancel ? abortControllerMap.get(command as AbortCommand) ?? abortControllerMap.get(ABORT_COMMANDS.All) : undefined; return processHTTPRequest(url, type, formData, abortSignalController?.signal); } -function cancelPendingRequests(command: AbortCommand = READ_COMMANDS.ALL) { - const controller = abortControllerMap.get(command) ?? abortControllerMap.get(READ_COMMANDS.ALL); +function cancelPendingRequests(command: AbortCommand = ABORT_COMMANDS.All) { + const controller = abortControllerMap.get(command) ?? abortControllerMap.get(ABORT_COMMANDS.All); controller?.abort(); From c0ce318e2d206e2f5a380ca6de3c22955146ff0e Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Thu, 23 May 2024 19:46:13 +0200 Subject: [PATCH 4/6] feat: add hook for canceling search request --- src/hooks/useCancelSearchOnModalClose.ts | 17 +++++++++++++++++ src/pages/ChatFinderPage/index.tsx | 6 ++---- src/pages/NewChatSelectorPage.tsx | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/hooks/useCancelSearchOnModalClose.ts diff --git a/src/hooks/useCancelSearchOnModalClose.ts b/src/hooks/useCancelSearchOnModalClose.ts new file mode 100644 index 000000000000..5f92937cce24 --- /dev/null +++ b/src/hooks/useCancelSearchOnModalClose.ts @@ -0,0 +1,17 @@ +import {useNavigation} from '@react-navigation/native'; +import {useEffect} from 'react'; +import {READ_COMMANDS} from '@libs/API/types'; +import HttpUtils from '@libs/HttpUtils'; + +const useCancelSearchOnModalClose = () => { + const navigation = useNavigation(); + useEffect(() => { + const unsubscribe = navigation.addListener('beforeRemove', () => { + HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); + }); + + return unsubscribe; + }, [navigation]); +}; + +export default useCancelSearchOnModalClose; diff --git a/src/pages/ChatFinderPage/index.tsx b/src/pages/ChatFinderPage/index.tsx index 23972b8f0913..3d6c735758f3 100644 --- a/src/pages/ChatFinderPage/index.tsx +++ b/src/pages/ChatFinderPage/index.tsx @@ -8,12 +8,11 @@ import {useOptionsList} from '@components/OptionListContextProvider'; import ScreenWrapper from '@components/ScreenWrapper'; import SelectionList from '@components/SelectionList'; import UserListItem from '@components/SelectionList/UserListItem'; +import useCancelSearchOnModalClose from '@hooks/useCancelSearchOnModalClose'; import useDebouncedState from '@hooks/useDebouncedState'; import useDismissedReferralBanners from '@hooks/useDismissedReferralBanners'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; -import {READ_COMMANDS} from '@libs/API/types'; -import HttpUtils from '@libs/HttpUtils'; import type {MaybePhraseKey} from '@libs/Localize'; import Navigation from '@libs/Navigation/Navigation'; import type {RootStackParamList} from '@libs/Navigation/types'; @@ -63,6 +62,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa const offlineMessage: MaybePhraseKey = isOffline ? [`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] : ''; const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState(''); + useCancelSearchOnModalClose(); useEffect(() => { Timing.start(CONST.TIMING.CHAT_FINDER_RENDER); @@ -145,8 +145,6 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa return; } - HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); - if (option.reportID) { setSearchValue(''); Navigation.dismissModal(option.reportID); diff --git a/src/pages/NewChatSelectorPage.tsx b/src/pages/NewChatSelectorPage.tsx index 6919dce33474..4cccb6a87fcd 100755 --- a/src/pages/NewChatSelectorPage.tsx +++ b/src/pages/NewChatSelectorPage.tsx @@ -3,6 +3,7 @@ import React from 'react'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import TabSelector from '@components/TabSelector/TabSelector'; +import useCancelSearchOnModalClose from '@hooks/useCancelSearchOnModalClose'; import useLocalize from '@hooks/useLocalize'; import OnyxTabNavigator, {TopTab} from '@libs/Navigation/OnyxTabNavigator'; import CONST from '@src/CONST'; @@ -12,6 +13,7 @@ import WorkspaceNewRoomPage from './workspace/WorkspaceNewRoomPage'; function NewChatSelectorPage() { const {translate} = useLocalize(); const navigation = useNavigation(); + useCancelSearchOnModalClose(); return ( Date: Fri, 24 May 2024 10:15:12 +0200 Subject: [PATCH 5/6] refactor: adjust types --- src/libs/HttpUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/HttpUtils.ts b/src/libs/HttpUtils.ts index a62efe86dd66..b254303d1784 100644 --- a/src/libs/HttpUtils.ts +++ b/src/libs/HttpUtils.ts @@ -16,10 +16,10 @@ let shouldForceOffline = false; const ABORT_COMMANDS = { All: 'All', - SearchForReports: READ_COMMANDS.SEARCH_FOR_REPORTS, + [READ_COMMANDS.SEARCH_FOR_REPORTS]: READ_COMMANDS.SEARCH_FOR_REPORTS, } as const; -type AbortCommand = (typeof ABORT_COMMANDS)[keyof typeof ABORT_COMMANDS]; +type AbortCommand = keyof typeof ABORT_COMMANDS; Onyx.connect({ key: ONYXKEYS.NETWORK, From 56989c91c0c77d22bfa2aa3103425706d675d365 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Mon, 27 May 2024 16:27:39 +0200 Subject: [PATCH 6/6] feat: add cancel function to all right modal panels --- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 13 ++++++++++++- src/pages/NewChatSelectorPage.tsx | 2 -- src/pages/RoomInvitePage.tsx | 4 ++++ .../iou/request/step/IOURequestStepParticipants.tsx | 3 +++ src/pages/tasks/TaskAssigneeSelectorModal.tsx | 3 +++ .../tasks/TaskShareDestinationSelectorModal.tsx | 3 +++ src/pages/workspace/WorkspaceInvitePage.tsx | 3 +++ 7 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index ad437f08523c..f9b1c5cbeb0c 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -7,6 +7,8 @@ import useOnboardingLayout from '@hooks/useOnboardingLayout'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; +import {READ_COMMANDS} from '@libs/API/types'; +import HttpUtils from '@libs/HttpUtils'; import KeyboardShortcut from '@libs/KeyboardShortcut'; import Log from '@libs/Log'; import getCurrentUrl from '@libs/Navigation/currentUrl'; @@ -157,6 +159,15 @@ const modalScreenListeners = { }, }; +// Extended modal screen listeners with additional cancellation of pending requests +const modalScreenListenersWithCancelSearch = { + ...modalScreenListeners, + beforeRemove: () => { + modalScreenListeners.beforeRemove(); + HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); + }, +}; + function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDAppliedToClient}: AuthScreensProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -351,7 +362,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie name={NAVIGATORS.RIGHT_MODAL_NAVIGATOR} options={screenOptions.rightModalNavigator} component={RightModalNavigator} - listeners={modalScreenListeners} + listeners={modalScreenListenersWithCancelSearch} /> ReportUtils.getReportName(report), [report]); const inviteUsers = useCallback(() => { + HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); + if (!validate()) { return; } diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.tsx b/src/pages/iou/request/step/IOURequestStepParticipants.tsx index e0be24db5c85..189e204e810b 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.tsx +++ b/src/pages/iou/request/step/IOURequestStepParticipants.tsx @@ -4,7 +4,9 @@ import {withOnyx} from 'react-native-onyx'; import FormHelpMessage from '@components/FormHelpMessage'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import {READ_COMMANDS} from '@libs/API/types'; import DistanceRequestUtils from '@libs/DistanceRequestUtils'; +import HttpUtils from '@libs/HttpUtils'; import * as IOUUtils from '@libs/IOUUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; @@ -84,6 +86,7 @@ function IOURequestStepParticipants({ const addParticipant = useCallback( (val: Participant[]) => { + HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); IOU.setMoneyRequestParticipants(transactionID, val); const rateID = DistanceRequestUtils.getCustomUnitRateID(val[0]?.reportID ?? ''); IOU.setCustomUnitRateID(transactionID, rateID); diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index 3116b8a84152..e8fe2926a7b6 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -22,6 +22,8 @@ import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import * as ReportActions from '@libs/actions/Report'; +import {READ_COMMANDS} from '@libs/API/types'; +import HttpUtils from '@libs/HttpUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -158,6 +160,7 @@ function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalPro const selectReport = useCallback( (option: ListItem) => { + HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); if (!option) { return; } diff --git a/src/pages/tasks/TaskShareDestinationSelectorModal.tsx b/src/pages/tasks/TaskShareDestinationSelectorModal.tsx index 4d731d59a9e7..445ec2741583 100644 --- a/src/pages/tasks/TaskShareDestinationSelectorModal.tsx +++ b/src/pages/tasks/TaskShareDestinationSelectorModal.tsx @@ -11,6 +11,8 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import * as ReportActions from '@libs/actions/Report'; +import {READ_COMMANDS} from '@libs/API/types'; +import HttpUtils from '@libs/HttpUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -21,6 +23,7 @@ import ROUTES from '@src/ROUTES'; import type {Report} from '@src/types/onyx'; const selectReportHandler = (option: unknown) => { + HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); const optionItem = option as ReportUtils.OptionData; if (!optionItem || !optionItem?.reportID) { diff --git a/src/pages/workspace/WorkspaceInvitePage.tsx b/src/pages/workspace/WorkspaceInvitePage.tsx index c564ce00542b..666570805c57 100644 --- a/src/pages/workspace/WorkspaceInvitePage.tsx +++ b/src/pages/workspace/WorkspaceInvitePage.tsx @@ -17,7 +17,9 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import * as ReportActions from '@libs/actions/Report'; +import {READ_COMMANDS} from '@libs/API/types'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; +import HttpUtils from '@libs/HttpUtils'; import * as LoginUtils from '@libs/LoginUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; @@ -233,6 +235,7 @@ function WorkspaceInvitePage({route, betas, invitedEmailsToAccountIDsDraft, poli if (!isValid) { return; } + HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); const invitedEmailsToAccountIDs: InvitedEmailsToAccountIDs = {}; selectedOptions.forEach((option) => {