From fb04e6d6a69a0a9ed2e9607a9fa8604950157021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Obudzi=C5=84ski?= Date: Mon, 2 Nov 2026 14:49:30 +0100 Subject: [PATCH] perf: skip draft transaction updates in the hidden Spend tab --- src/hooks/useSearchTypeMenuSections.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hooks/useSearchTypeMenuSections.ts b/src/hooks/useSearchTypeMenuSections.ts index 9550793213ab..938a84bb4bc5 100644 --- a/src/hooks/useSearchTypeMenuSections.ts +++ b/src/hooks/useSearchTypeMenuSections.ts @@ -46,6 +46,10 @@ const policyMapper = (policy: OnyxEntry): OnyxEntry => travelSettings: policy.travelSettings, }; +// The draft IDs are only used by an empty state button, which needs a focused screen. An unfocused consumer ignores draft +// writes, so starting a Create expense flow (which writes a draft) does not re-render a hidden tab. +const noDraftTransactionIDsSelector = (): string[] => []; + const currentUserLoginAndAccountIDSelector = (session: OnyxEntry) => ({ email: session?.email, accountID: session?.accountID, @@ -54,8 +58,8 @@ const currentUserLoginAndAccountIDSelector = (session: OnyxEntry) => ({ /** * Get a list of all search groupings, along with their search items. * - * `isScreenFocused` gates the reports-awaiting-approval watch so an off-screen consumer stops recomputing it. It - * defaults to `true` (always watch) for consumers rendered outside a navigator or where focus can't be tracked + * `isScreenFocused` gates the reports-awaiting-approval watch and the draft transaction IDs so an off-screen consumer stops + * recomputing them. It defaults to `true` (always watch) for consumers rendered outside a navigator or where focus can't be tracked * reliably, so this hook never depends on a navigation context itself. */ const useSearchTypeMenuSections = (isScreenFocused = true) => { @@ -67,7 +71,9 @@ const useSearchTypeMenuSections = (isScreenFocused = true) => { const [allPolicies] = useMappedPolicies(policyMapper); const [currentUserLoginAndAccountID] = useOnyx(ONYXKEYS.SESSION, {selector: currentUserLoginAndAccountIDSelector}); const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES); - const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftIDsSelector}); + const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, { + selector: isScreenFocused ? validTransactionDraftIDsSelector : noDraftTransactionIDsSelector, + }); const [isTrackIntentUser] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {selector: isTrackIntentUserSelector}); // Migrated Control workspaces leave `areRulesEnabled` undefined; Violations by submitter then depends on // Classic category rules stored on POLICY_CATEGORIES. No selector: mapping this collection would still be