From be9e4c8bcb22892bacf8924a00825a05bb85c6db Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 10 Jun 2026 22:11:25 +0100 Subject: [PATCH 1/4] apply changes from #92299 --- .../home/YourSpendSection/useYourSpendData.ts | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/pages/home/YourSpendSection/useYourSpendData.ts b/src/pages/home/YourSpendSection/useYourSpendData.ts index 87d18f1ae4e6..9a55239ed25d 100644 --- a/src/pages/home/YourSpendSection/useYourSpendData.ts +++ b/src/pages/home/YourSpendSection/useYourSpendData.ts @@ -10,6 +10,7 @@ import {search} from '@libs/actions/Search'; import {getDisplayableExpensifyCards, getDisplayableThirdPartyCards, isPersonalCard, lastFourNumbersFromCardName} from '@libs/CardUtils'; import {arePaymentsEnabled, isPaidGroupPolicy} from '@libs/PolicyUtils'; import {buildSearchQueryJSON} from '@libs/SearchQueryUtils'; +import {getSuggestedSearches, getSuggestedSearchesVisibility, TODO_SEARCH_KEYS} from '@libs/SearchUIUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Card, Policy, Report} from '@src/types/onyx'; @@ -129,7 +130,7 @@ function getYourSpendRowState({isApplicable, isOffline, searchResults}: GetYourS } function useYourSpendData(): UseYourSpendDataReturn { - const {accountID} = useCurrentUserPersonalDetails(); + const {accountID, email} = useCurrentUserPersonalDetails(); const {isOffline} = useNetwork(); const isFocused = useIsFocused(); @@ -365,6 +366,11 @@ function useYourSpendData(): UseYourSpendDataReturn { // (which changes the policyID filter), or the set of OUTSTANDING reports changes. const applicabilityKey = `${isApprovalApplicable ? 1 : 0}${isPaymentApplicable ? 1 : 0}|${paidGroupPolicyIDs.join(',')}|${outstandingReportsSignature ?? ''}`; + // The `cardFeedsByPolicy` and `defaultExpensifyCard` params are not passed + // because they have no effect on the `TODO_SEARCH_KEYS` (and we are only interested in `TODO_SEARCH_KEYS`) + const {visibility: suggestedSearchesVisibility} = getSuggestedSearchesVisibility(email, {}, policies, undefined); + const suggestedSearches = getSuggestedSearches(accountID); + const fireSearches = useEffectEvent(() => { if (isOffline) { return; @@ -406,6 +412,25 @@ function useYourSpendData(): UseYourSpendDataReturn { shouldUpdateLastSearchParams: false, }); } + for (const searchKey of TODO_SEARCH_KEYS) { + const isVisible = suggestedSearchesVisibility[searchKey]; + if (!isVisible) { + continue; + } + const queryJSON = suggestedSearches[searchKey].searchQueryJSON; + if (!queryJSON) { + continue; + } + search({ + queryJSON, + searchKey, + offset: 0, + isOffline, + isLoading: false, + shouldCalculateTotals: false, + shouldUpdateLastSearchParams: false, + }); + } }); useEffect(() => { @@ -413,7 +438,7 @@ function useYourSpendData(): UseYourSpendDataReturn { return; } fireSearches(); - }, [isFocused, isOffline, displayableCardIDsKey, applicabilityKey]); + }, [isFocused, isOffline, displayableCardIDsKey, applicabilityKey, suggestedSearchesVisibility]); return { approvalRowState, From d455db294fa4b07ec8ed7f46716d25a6c5ee3acd Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 10 Jun 2026 22:42:16 +0100 Subject: [PATCH 2/4] fix infinite search loop --- .../home/YourSpendSection/useYourSpendData.ts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/pages/home/YourSpendSection/useYourSpendData.ts b/src/pages/home/YourSpendSection/useYourSpendData.ts index 9a55239ed25d..bae624ddee2a 100644 --- a/src/pages/home/YourSpendSection/useYourSpendData.ts +++ b/src/pages/home/YourSpendSection/useYourSpendData.ts @@ -362,14 +362,20 @@ function useYourSpendData(): UseYourSpendDataReturn { const approvalTotals: YourSpendRowTotals = shouldUseCachedApproval && cachedApprovalReady ? cachedApprovalReady : approvalTotalsRaw; const paymentTotals: YourSpendRowTotals = shouldUseCachedPayment && cachedPaymentReady ? cachedPaymentReady : paymentTotalsRaw; - // Re-fires the search effect when applicability flips, the user joins/leaves a workspace - // (which changes the policyID filter), or the set of OUTSTANDING reports changes. - const applicabilityKey = `${isApprovalApplicable ? 1 : 0}${isPaymentApplicable ? 1 : 0}|${paidGroupPolicyIDs.join(',')}|${outstandingReportsSignature ?? ''}`; - // The `cardFeedsByPolicy` and `defaultExpensifyCard` params are not passed // because they have no effect on the `TODO_SEARCH_KEYS` (and we are only interested in `TODO_SEARCH_KEYS`) - const {visibility: suggestedSearchesVisibility} = getSuggestedSearchesVisibility(email, {}, policies, undefined); - const suggestedSearches = getSuggestedSearches(accountID); + const suggestedSearchesVisibility = useMemo(() => getSuggestedSearchesVisibility(email, {}, policies, undefined).visibility, [email, policies]); + const suggestedSearches = useMemo(() => getSuggestedSearches(accountID), [accountID]); + + // Re-fires the search effect when applicability flips, the user joins/leaves a workspace + // (which changes the policyID filter), or the set of OUTSTANDING reports changes. + const applicabilityKey = [ + isApprovalApplicable ? 1 : 0, + isPaymentApplicable ? 1 : 0, + paidGroupPolicyIDs.join(','), + outstandingReportsSignature ?? '', + [...TODO_SEARCH_KEYS].map((k) => (suggestedSearchesVisibility[k] ? 1 : 0)).join(''), + ].join('|'); const fireSearches = useEffectEvent(() => { if (isOffline) { @@ -438,7 +444,7 @@ function useYourSpendData(): UseYourSpendDataReturn { return; } fireSearches(); - }, [isFocused, isOffline, displayableCardIDsKey, applicabilityKey, suggestedSearchesVisibility]); + }, [isFocused, isOffline, displayableCardIDsKey, applicabilityKey]); return { approvalRowState, From f90dc57f6cad27ab22d8b5ff31194272f3d5c847 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 10 Jun 2026 23:01:16 +0100 Subject: [PATCH 3/4] remove useMemo --- src/pages/home/YourSpendSection/useYourSpendData.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/YourSpendSection/useYourSpendData.ts b/src/pages/home/YourSpendSection/useYourSpendData.ts index bae624ddee2a..55c3c71b9e00 100644 --- a/src/pages/home/YourSpendSection/useYourSpendData.ts +++ b/src/pages/home/YourSpendSection/useYourSpendData.ts @@ -364,8 +364,8 @@ function useYourSpendData(): UseYourSpendDataReturn { // The `cardFeedsByPolicy` and `defaultExpensifyCard` params are not passed // because they have no effect on the `TODO_SEARCH_KEYS` (and we are only interested in `TODO_SEARCH_KEYS`) - const suggestedSearchesVisibility = useMemo(() => getSuggestedSearchesVisibility(email, {}, policies, undefined).visibility, [email, policies]); - const suggestedSearches = useMemo(() => getSuggestedSearches(accountID), [accountID]); + const suggestedSearchesVisibility = getSuggestedSearchesVisibility(email, {}, policies, undefined).visibility; + const suggestedSearches = getSuggestedSearches(accountID); // Re-fires the search effect when applicability flips, the user joins/leaves a workspace // (which changes the policyID filter), or the set of OUTSTANDING reports changes. From 694ef25562f8f4252786a13aceb84a0c1ad32d43 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 10 Jun 2026 23:04:36 +0100 Subject: [PATCH 4/4] add accountID as useEffect depedency --- src/pages/home/YourSpendSection/useYourSpendData.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/YourSpendSection/useYourSpendData.ts b/src/pages/home/YourSpendSection/useYourSpendData.ts index 55c3c71b9e00..d181cfa6d8ce 100644 --- a/src/pages/home/YourSpendSection/useYourSpendData.ts +++ b/src/pages/home/YourSpendSection/useYourSpendData.ts @@ -444,7 +444,7 @@ function useYourSpendData(): UseYourSpendDataReturn { return; } fireSearches(); - }, [isFocused, isOffline, displayableCardIDsKey, applicabilityKey]); + }, [isFocused, isOffline, displayableCardIDsKey, applicabilityKey, accountID]); return { approvalRowState,