From 0c7fb17a2a89b5ab1ae19e5ca91d25606ffe5dcf Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Thu, 26 Feb 2026 12:36:28 +0100 Subject: [PATCH 1/9] Move isComposerFullSize subscription into ReportFooter ReportFooter is the only consumer of isComposerFullSize. By owning the subscription internally, we remove two parent-level Onyx subscriptions (ReportScreen + MoneyRequestReportView), avoiding unnecessary re-renders of those heavy components when the composer size changes. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../MoneyRequestReportView/MoneyRequestReportView.tsx | 3 --- src/pages/inbox/ReportScreen.tsx | 2 -- src/pages/inbox/report/ReportFooter.tsx | 6 +----- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx index cff0e1ef31de..da3aba3361e1 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx @@ -105,7 +105,6 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe const reportID = report?.reportID; const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP); - const [isComposerFullSize = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportID}`); const {reportPendingAction, reportErrors} = getReportOfflinePendingActionAndErrors(report); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.chatReportID)}`); @@ -236,7 +235,6 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe reportMetadata={reportMetadata} policy={policy} pendingAction={reportPendingAction} - isComposerFullSize={!!isComposerFullSize} lastReportAction={lastReportAction} // If the report is from the 'Send Money' flow, we add the comment to the `iou` report because for these we don't combine reportActions even if there is a single transaction (they always have a single transaction) transactionThreadReportID={isSentMoneyReport ? undefined : transactionThreadReportID} @@ -309,7 +307,6 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe reportMetadata={reportMetadata} policy={policy} pendingAction={reportPendingAction} - isComposerFullSize={!!isComposerFullSize} lastReportAction={lastReportAction} reportTransactions={transactions} // If the report is from the 'Send Money' flow, we add the comment to the `iou` report because for these we don't combine reportActions even if there is a single transaction (they always have a single transaction) diff --git a/src/pages/inbox/ReportScreen.tsx b/src/pages/inbox/ReportScreen.tsx index 2c89d36fbfba..9a67ab68015f 100644 --- a/src/pages/inbox/ReportScreen.tsx +++ b/src/pages/inbox/ReportScreen.tsx @@ -168,7 +168,6 @@ function ReportScreen({route, navigation, isInSidePanel = false}: ReportScreenPr const [reportOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true}); const [parentReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportOnyx?.parentReportID}`, {allowStaleData: true}); - const [isComposerFullSize = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportIDFromRoute}`); const [userLeavingStatus = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM}${reportIDFromRoute}`); const [reportNameValuePairsOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportIDFromRoute}`, {allowStaleData: true}); const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {allowStaleData: true}); @@ -1063,7 +1062,6 @@ function ReportScreen({route, navigation, isInSidePanel = false}: ReportScreenPr reportMetadata={reportMetadata} policy={policy} pendingAction={reportPendingAction} - isComposerFullSize={!!isComposerFullSize} lastReportAction={lastReportAction} reportTransactions={reportTransactions} // If the report is from the 'Send Money' flow, we add the comment to the `iou` report because for these we don't combine reportActions even if there is a single transaction (they always have a single transaction) diff --git a/src/pages/inbox/report/ReportFooter.tsx b/src/pages/inbox/report/ReportFooter.tsx index 369ef7cb67d6..44989cd92b46 100644 --- a/src/pages/inbox/report/ReportFooter.tsx +++ b/src/pages/inbox/report/ReportFooter.tsx @@ -66,9 +66,6 @@ type ReportFooterProps = { /** The pending action when we are adding a chat */ pendingAction?: PendingAction; - /** Whether the composer is in full size */ - isComposerFullSize?: boolean; - /** A method to call when the input is focus */ onComposerFocus?: () => void; @@ -85,7 +82,6 @@ function ReportFooter({ report = {reportID: '-1'}, reportMetadata, policy, - isComposerFullSize = false, onComposerBlur, onComposerFocus, reportTransactions, @@ -107,6 +103,7 @@ function ReportFooter({ const [isBlockedFromChat] = useOnyx(ONYXKEYS.NVP_BLOCKED_FROM_CHAT, { selector: isBlockedFromChatSelector, }); + const [isComposerFullSize = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${report.reportID}`); const chatFooterStyles = {...styles.chatFooter, minHeight: !isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0}; const isReportArchived = useReportIsArchived(report?.reportID); @@ -285,7 +282,6 @@ export default memo( // Report comes from useOnyx - reference is stable prevProps.report === nextProps.report && prevProps.pendingAction === nextProps.pendingAction && - prevProps.isComposerFullSize === nextProps.isComposerFullSize && prevProps.lastReportAction === nextProps.lastReportAction && // reportMetadata comes from useOnyx - reference is stable prevProps.reportMetadata === nextProps.reportMetadata && From a2195478d613e6b9f4b5a14f006c0b8f59687a89 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Thu, 26 Feb 2026 14:55:05 +0100 Subject: [PATCH 2/9] Tighten ReportFooter interface and remove manual memo comparators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Internalize policy, reportMetadata, and pendingAction into ReportFooter via useOnyx selectors and derivation from report, removing 3 props from the public interface. Remove manual memo() wrappers from ReportFooter, ReportScreen, and HeaderView — the React Compiler handles memoization. Also remove manual useCallback wrappers that the compiler auto-memoizes. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../MoneyRequestReportView.tsx | 6 - src/pages/inbox/HeaderView.tsx | 4 +- src/pages/inbox/ReportScreen.tsx | 9 +- src/pages/inbox/report/ReportFooter.tsx | 198 ++++++++---------- 4 files changed, 88 insertions(+), 129 deletions(-) diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx index da3aba3361e1..791cbbe07303 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx @@ -232,9 +232,6 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe {shouldDisplayReportFooter ? ( deepEqual(prevProps.route, nextProps.route)); +export default ReportScreen; diff --git a/src/pages/inbox/report/ReportFooter.tsx b/src/pages/inbox/report/ReportFooter.tsx index 44989cd92b46..1643028efb5d 100644 --- a/src/pages/inbox/report/ReportFooter.tsx +++ b/src/pages/inbox/report/ReportFooter.tsx @@ -1,6 +1,6 @@ import {isBlockedFromChatSelector} from '@selectors/BlockedFromChat'; import {Str} from 'expensify-common'; -import React, {memo, useCallback, useEffect, useState} from 'react'; +import React, {useEffect, useState} from 'react'; import {Keyboard, View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import AnonymousReportFooter from '@components/AnonymousReportFooter'; @@ -26,10 +26,10 @@ import {addComment} from '@libs/actions/Report'; import {createTaskAndNavigate, setNewOptimisticAssignee} from '@libs/actions/Task'; import {isEmailPublicDomain} from '@libs/LoginUtils'; import {addDomainToShortMention} from '@libs/ParsingUtils'; -import {isPolicyAdmin} from '@libs/PolicyUtils'; import { canUserPerformWriteAction, canWriteInReport as canWriteInReportUtil, + getReportOfflinePendingActionAndErrors, isAdminsOnlyPostingRoom as isAdminsOnlyPostingRoomUtil, isArchivedNonExpenseReport, isPublicRoom, @@ -40,32 +40,25 @@ import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxTypes from '@src/types/onyx'; -import type {PendingAction} from '@src/types/onyx/OnyxCommon'; import ReportActionCompose from './ReportActionCompose/ReportActionCompose'; import SystemChatReportFooterMessage from './SystemChatReportFooterMessage'; +const policyRoleSelector = (policy: OnyxEntry) => policy?.role; +const isLoadingInitialReportActionsSelector = (reportMetadata: OnyxEntry) => reportMetadata?.isLoadingInitialReportActions; + type ReportFooterProps = { /** Report object for the current report */ report?: OnyxTypes.Report; - /** Report metadata */ - reportMetadata?: OnyxEntry; - /** Report transactions */ reportTransactions?: OnyxEntry; /** The ID of the transaction thread report if there is a single transaction */ transactionThreadReportID?: string; - /** The policy of the report */ - policy: OnyxEntry; - /** The last report action */ lastReportAction?: OnyxEntry; - /** The pending action when we are adding a chat */ - pendingAction?: PendingAction; - /** A method to call when the input is focus */ onComposerFocus?: () => void; @@ -76,18 +69,7 @@ type ReportFooterProps = { isInSidePanel?: boolean; }; -function ReportFooter({ - lastReportAction, - pendingAction, - report = {reportID: '-1'}, - reportMetadata, - policy, - onComposerBlur, - onComposerFocus, - reportTransactions, - transactionThreadReportID, - isInSidePanel, -}: ReportFooterProps) { +function ReportFooter({lastReportAction, report = {reportID: '-1'}, onComposerBlur, onComposerFocus, reportTransactions, transactionThreadReportID, isInSidePanel}: ReportFooterProps) { const styles = useThemeStyles(); const {isOffline} = useNetwork(); const {translate} = useLocalize(); @@ -104,7 +86,15 @@ function ReportFooter({ selector: isBlockedFromChatSelector, }); const [isComposerFullSize = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${report.reportID}`); + const [policyRole] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, { + selector: policyRoleSelector, + }); + const [isLoadingInitialReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`, { + selector: isLoadingInitialReportActionsSelector, + }); + const {reportPendingAction} = getReportOfflinePendingActionAndErrors(report); + const isUserPolicyAdmin = policyRole === CONST.POLICY.ROLE.ADMIN; const chatFooterStyles = {...styles.chatFooter, minHeight: !isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0}; const isReportArchived = useReportIsArchived(report?.reportID); const ancestors = useAncestors(report); @@ -113,98 +103,90 @@ function ReportFooter({ const isSmallSizeLayout = windowWidth - (shouldUseNarrowLayout ? 0 : variables.sideBarWithLHBWidth) < variables.anonymousReportFooterBreakpoint; // If a user just signed in and is viewing a public report, optimistically show the composer while loading the report, since they will have write access when the response comes back. - const shouldShowComposerOptimistically = !isAnonymousUser && isPublicRoom(report) && !!reportMetadata?.isLoadingInitialReportActions; + const shouldShowComposerOptimistically = !isAnonymousUser && isPublicRoom(report) && !!isLoadingInitialReportActions; const canPerformWriteAction = canUserPerformWriteAction(report, isReportArchived) ?? shouldShowComposerOptimistically; const shouldHideComposer = !canPerformWriteAction || isBlockedFromChat; const canWriteInReport = canWriteInReportUtil(report); const isSystemChat = isSystemChatUtil(report); const isAdminsOnlyPostingRoom = isAdminsOnlyPostingRoomUtil(report); - const isUserPolicyAdmin = isPolicyAdmin(policy); const allPersonalDetails = usePersonalDetails(); const {availableLoginsList} = useShortMentionsList(); const currentUserEmail = personalDetail.email ?? ''; - const handleCreateTask = useCallback( - (text: string): boolean => { - const match = text.match(CONST.REGEX.TASK_TITLE_WITH_OPTIONAL_SHORT_MENTION); - if (!match) { - return false; - } - let title = match[3] ? match[3].trim().replaceAll('\n', ' ') : undefined; - if (!title) { - return false; - } + const handleCreateTask = (text: string): boolean => { + const match = text.match(CONST.REGEX.TASK_TITLE_WITH_OPTIONAL_SHORT_MENTION); + if (!match) { + return false; + } + let title = match[3] ? match[3].trim().replaceAll('\n', ' ') : undefined; + if (!title) { + return false; + } - const mention = match[1] ? match[1].trim() : ''; - const currentUserPrivateDomain = isEmailPublicDomain(currentUserEmail ?? '') ? '' : Str.extractEmailDomain(currentUserEmail ?? ''); - const mentionWithDomain = addDomainToShortMention(mention, availableLoginsList, currentUserPrivateDomain) ?? mention; - const isValidMention = Str.isValidEmail(mentionWithDomain); + const mention = match[1] ? match[1].trim() : ''; + const currentUserPrivateDomain = isEmailPublicDomain(currentUserEmail ?? '') ? '' : Str.extractEmailDomain(currentUserEmail ?? ''); + const mentionWithDomain = addDomainToShortMention(mention, availableLoginsList, currentUserPrivateDomain) ?? mention; + const isValidMention = Str.isValidEmail(mentionWithDomain); - let assignee: OnyxEntry; - let assigneeChatReport; - if (mentionWithDomain) { - if (isValidMention) { - assignee = Object.values(allPersonalDetails ?? {}).find((value) => value?.login === mentionWithDomain) ?? undefined; - if (!Object.keys(assignee ?? {}).length) { - const optimisticDataForNewAssignee = setNewOptimisticAssignee(personalDetail.accountID, { - accountID: generateAccountID(mentionWithDomain), - login: mentionWithDomain, - }); - assignee = optimisticDataForNewAssignee.assignee; - assigneeChatReport = optimisticDataForNewAssignee.assigneeReport; - } - } else { - // If the mention is not valid, include it on the title. - // The mention could be invalid if it's a short mention and failed to be converted to a full mention. - title = `@${mentionWithDomain} ${title}`; + let assignee: OnyxEntry; + let assigneeChatReport; + if (mentionWithDomain) { + if (isValidMention) { + assignee = Object.values(allPersonalDetails ?? {}).find((value) => value?.login === mentionWithDomain) ?? undefined; + if (!Object.keys(assignee ?? {}).length) { + const optimisticDataForNewAssignee = setNewOptimisticAssignee(personalDetail.accountID, { + accountID: generateAccountID(mentionWithDomain), + login: mentionWithDomain, + }); + assignee = optimisticDataForNewAssignee.assignee; + assigneeChatReport = optimisticDataForNewAssignee.assigneeReport; } + } else { + // If the mention is not valid, include it on the title. + // The mention could be invalid if it's a short mention and failed to be converted to a full mention. + title = `@${mentionWithDomain} ${title}`; } - createTaskAndNavigate({ - parentReport: report, - title, - description: '', - assigneeEmail: assignee?.login ?? '', - currentUserAccountID: personalDetail.accountID, - currentUserEmail, - assigneeAccountID: assignee?.accountID, - assigneeChatReport, - policyID: report.policyID, - isCreatedUsingMarkdown: true, - quickAction, - ancestors, - }); - return true; - }, - [allPersonalDetails, ancestors, availableLoginsList, currentUserEmail, personalDetail.accountID, quickAction, report], - ); + } + createTaskAndNavigate({ + parentReport: report, + title, + description: '', + assigneeEmail: assignee?.login ?? '', + currentUserAccountID: personalDetail.accountID, + currentUserEmail, + assigneeAccountID: assignee?.accountID, + assigneeChatReport, + policyID: report.policyID, + isCreatedUsingMarkdown: true, + quickAction, + ancestors, + }); + return true; + }; const [targetReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID ?? report.reportID}`); const targetReportAncestors = useAncestors(targetReport); - const onSubmitComment = useCallback( - (text: string, reportActionID?: string) => { - const isTaskCreated = handleCreateTask(text); - if (isTaskCreated) { - return; - } - // If we are adding an action on an expense report that only has a single transaction thread child report, we need to add the action to the transaction thread instead. - // This is because we need it to be associated with the transaction thread and not the expense report in order for conversational corrections to work as expected. - addComment({ - report: targetReport, - notifyReportID: report.reportID, - ancestors: targetReportAncestors, - text, - timezoneParam: personalDetail.timezone ?? CONST.DEFAULT_TIME_ZONE, - currentUserAccountID: personalDetail.accountID, - shouldPlaySound: true, - isInSidePanel, - reportActionID, - }); - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [report.reportID, handleCreateTask, targetReport, targetReportAncestors, isInSidePanel, personalDetail.accountID], - ); + const onSubmitComment = (text: string, reportActionID?: string) => { + const isTaskCreated = handleCreateTask(text); + if (isTaskCreated) { + return; + } + // If we are adding an action on an expense report that only has a single transaction thread child report, we need to add the action to the transaction thread instead. + // This is because we need it to be associated with the transaction thread and not the expense report in order for conversational corrections to work as expected. + addComment({ + report: targetReport, + notifyReportID: report.reportID, + ancestors: targetReportAncestors, + text, + timezoneParam: personalDetail.timezone ?? CONST.DEFAULT_TIME_ZONE, + currentUserAccountID: personalDetail.accountID, + shouldPlaySound: true, + isInSidePanel, + reportActionID, + }); + }; const [didHideComposerInput, setDidHideComposerInput] = useState(!shouldShowComposeInput); @@ -212,6 +194,8 @@ function ReportFooter({ if (didHideComposerInput || shouldShowComposeInput) { return; } + // This is an intentional one-way latch: once the composer input has been hidden, it stays hidden. + // eslint-disable-next-line react-hooks/set-state-in-effect setDidHideComposerInput(true); }, [shouldShowComposeInput, didHideComposerInput]); @@ -262,7 +246,7 @@ function ReportFooter({ reportID={report.reportID} report={report} lastReportAction={lastReportAction} - pendingAction={pendingAction} + pendingAction={reportPendingAction} isComposerFullSize={isComposerFullSize} didHideComposerInput={didHideComposerInput} reportTransactions={reportTransactions} @@ -276,18 +260,4 @@ function ReportFooter({ ); } -export default memo( - ReportFooter, - (prevProps, nextProps) => - // Report comes from useOnyx - reference is stable - prevProps.report === nextProps.report && - prevProps.pendingAction === nextProps.pendingAction && - prevProps.lastReportAction === nextProps.lastReportAction && - // reportMetadata comes from useOnyx - reference is stable - prevProps.reportMetadata === nextProps.reportMetadata && - // policy comes from useOnyx - comparing nested properties which may be stable - prevProps.policy?.employeeList === nextProps.policy?.employeeList && - prevProps.policy?.role === nextProps.policy?.role && - // reportTransactions comes from useOnyx - reference is stable - prevProps.reportTransactions === nextProps.reportTransactions, -); +export default ReportFooter; From d7c53c2dc9684c9cb63dd4807d6a00f8c939f527 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Thu, 26 Feb 2026 15:23:40 +0100 Subject: [PATCH 3/9] Narrow HeaderView's expensive Onyx subscriptions with selectors Replace grandParentReportActions full-collection subscription with useParentReportAction hook, add selector for account (guideDetails only), and add selector for reportMetadata (pendingChatMembers only). Co-Authored-By: Claude Opus 4.6 (1M context) --- src/pages/inbox/HeaderView.tsx | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/pages/inbox/HeaderView.tsx b/src/pages/inbox/HeaderView.tsx index 31b98e034985..651f0e73cf9c 100644 --- a/src/pages/inbox/HeaderView.tsx +++ b/src/pages/inbox/HeaderView.tsx @@ -25,6 +25,7 @@ import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; +import useParentReportAction from '@hooks/useParentReportAction'; import usePolicy from '@hooks/usePolicy'; import useReportIsArchived from '@hooks/useReportIsArchived'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; @@ -78,9 +79,14 @@ import {callFunctionIfActionIsAllowed} from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import SCREENS from '@src/SCREENS'; -import type {Report, ReportAction} from '@src/types/onyx'; +import type {Account, Report, ReportAction, ReportMetadata} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +const accountGuideDetailsSelector = (account: OnyxEntry) => account?.guideDetails; + +const reportMetadataSelector = (reportMetadata: OnyxEntry): OnyxEntry => + reportMetadata ? {pendingChatMembers: reportMetadata.pendingChatMembers} : undefined; + type HeaderViewProps = { /** Toggles the navigationMenu open and closed */ onNavigationMenuButtonClicked: () => void; @@ -110,16 +116,16 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked, const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiverPolicyID}`); const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID) ?? getNonEmptyStringOnyxID(report?.reportID)}`); const [grandParentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReport?.parentReportID)}`); - const [grandParentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(parentReport?.parentReportID)}`); + const grandParentReportAction = useParentReportAction(parentReport); const policy = usePolicy(report?.policyID); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID); const shouldShowLoadingBar = useLoadingBarVisibility(); const [firstDayFreeTrial] = useOnyx(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL); const [lastDayFreeTrial] = useOnyx(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL); - const [account] = useOnyx(ONYXKEYS.ACCOUNT); + const [accountGuideDetails] = useOnyx(ONYXKEYS.ACCOUNT, {selector: accountGuideDetailsSelector}); const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`); - const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`); + const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`, {selector: reportMetadataSelector}); const isReportArchived = isArchivedReport(reportNameValuePairs); const {translate, localeCompare, formatPhoneNumber} = useLocalize(); @@ -144,7 +150,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked, // This is used to check if the report is a chat thread and has a parent invoice report. const isParentInvoiceAndIsChatThread = isChatThread && !!parentReport && isInvoiceReport(parentReport); const reportHeaderData = (!isTaskReport && !isChatThread && report?.parentReportID) || isParentInvoiceAndIsChatThread ? parentReport : report; - const isParentOneTransactionThread = isOneTransactionThread(parentReport, grandParentReport, grandParentReportActions?.[`${parentReport?.parentReportActionID}`]); + const isParentOneTransactionThread = isOneTransactionThread(parentReport, grandParentReport, grandParentReportAction); const parentNavigationReport = isParentOneTransactionThread ? parentReport : reportHeaderData; const isReportHeaderDataArchived = useReportIsArchived(reportHeaderData?.reportID); const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails(); @@ -185,9 +191,9 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked, }; const shouldShowGuideBooking = - !!account && - account?.guideDetails?.email !== CONST.EMAIL.CONCIERGE && - !!account?.guideDetails?.calendarLink && + !!accountGuideDetails && + accountGuideDetails?.email !== CONST.EMAIL.CONCIERGE && + !!accountGuideDetails?.calendarLink && isAdminRoom(report) && !!canUserPerformWriteAction(report, isReportArchived) && !isChatThread && From f0afa20fadf23f4df90c20373771ad8887cbe0cb Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Thu, 26 Feb 2026 16:08:53 +0100 Subject: [PATCH 4/9] Extract LoadingBar into HeaderLoadingBar to isolate SequentialQueue re-renders The useLoadingBarVisibility hook subscribes to PERSISTED_REQUESTS without a selector, causing HeaderView to re-render on every queue mutation. By extracting LoadingBar into a dedicated child component and adding boolean selectors to the hook, queue processing no longer triggers re-renders of HeaderView's ~50 local variables and deeply nested JSX. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hooks/useLoadingBarVisibility.ts | 15 +++++++++------ src/pages/inbox/HeaderLoadingBar.tsx | 12 ++++++++++++ src/pages/inbox/HeaderView.tsx | 6 ++---- 3 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 src/pages/inbox/HeaderLoadingBar.tsx diff --git a/src/hooks/useLoadingBarVisibility.ts b/src/hooks/useLoadingBarVisibility.ts index 70dba0557f77..9f67b6bff819 100644 --- a/src/hooks/useLoadingBarVisibility.ts +++ b/src/hooks/useLoadingBarVisibility.ts @@ -1,18 +1,24 @@ +import type {OnyxEntry} from 'react-native-onyx'; import {WRITE_COMMANDS} from '@libs/API/types'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {AnyRequest} from '@src/types/onyx'; import useNetwork from './useNetwork'; import useOnyx from './useOnyx'; // Commands that should trigger the LoadingBar to show const RELEVANT_COMMANDS = new Set([WRITE_COMMANDS.OPEN_APP, WRITE_COMMANDS.RECONNECT_APP, WRITE_COMMANDS.OPEN_REPORT, WRITE_COMMANDS.READ_NEWEST_ACTION]); +const persistedRequestsSelector = (requests: OnyxEntry) => !!requests?.some((r) => RELEVANT_COMMANDS.has(r.command) && !r.initiatedOffline); + +const ongoingRequestSelector = (request: OnyxEntry) => !!request && RELEVANT_COMMANDS.has(request.command); + /** * Hook that determines whether LoadingBar should be visible based on active queue requests * Shows LoadingBar when any of the RELEVANT_COMMANDS are being processed */ export default function useLoadingBarVisibility(): boolean { - const [persistedRequests] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS); - const [ongoingRequests] = useOnyx(ONYXKEYS.PERSISTED_ONGOING_REQUESTS); + const [hasRelevantPersistedRequests] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS, {selector: persistedRequestsSelector}); + const [hasRelevantOngoingRequest] = useOnyx(ONYXKEYS.PERSISTED_ONGOING_REQUESTS, {selector: ongoingRequestSelector}); const {isOffline} = useNetwork(); // Don't show loading bar if currently offline @@ -20,8 +26,5 @@ export default function useLoadingBarVisibility(): boolean { return false; } - const hasPersistedRequests = !!persistedRequests?.some((request) => RELEVANT_COMMANDS.has(request.command) && !request.initiatedOffline); - const hasOngoingRequests = !!ongoingRequests && RELEVANT_COMMANDS.has(ongoingRequests?.command); - - return hasPersistedRequests || hasOngoingRequests; + return !!hasRelevantPersistedRequests || !!hasRelevantOngoingRequest; } diff --git a/src/pages/inbox/HeaderLoadingBar.tsx b/src/pages/inbox/HeaderLoadingBar.tsx new file mode 100644 index 000000000000..935bf7f51c23 --- /dev/null +++ b/src/pages/inbox/HeaderLoadingBar.tsx @@ -0,0 +1,12 @@ +import LoadingBar from '@components/LoadingBar'; +import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; + +function HeaderLoadingBar() { + const {shouldUseNarrowLayout} = useResponsiveLayout(); + const shouldShowLoadingBar = useLoadingBarVisibility(); + + return ; +} + +export default HeaderLoadingBar; diff --git a/src/pages/inbox/HeaderView.tsx b/src/pages/inbox/HeaderView.tsx index 651f0e73cf9c..0b8af42091e5 100644 --- a/src/pages/inbox/HeaderView.tsx +++ b/src/pages/inbox/HeaderView.tsx @@ -7,7 +7,6 @@ import Button from '@components/Button'; import CaretWrapper from '@components/CaretWrapper'; import DisplayNames from '@components/DisplayNames'; import Icon from '@components/Icon'; -import LoadingBar from '@components/LoadingBar'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import OnboardingHelpDropdownButton from '@components/OnboardingHelpDropdownButton'; import ParentNavigationSubtitle from '@components/ParentNavigationSubtitle'; @@ -22,7 +21,6 @@ import Tooltip from '@components/Tooltip'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useHasTeam2025Pricing from '@hooks/useHasTeam2025Pricing'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; -import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import useParentReportAction from '@hooks/useParentReportAction'; @@ -81,6 +79,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import SCREENS from '@src/SCREENS'; import type {Account, Report, ReportAction, ReportMetadata} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import HeaderLoadingBar from './HeaderLoadingBar'; const accountGuideDetailsSelector = (account: OnyxEntry) => account?.guideDetails; @@ -120,7 +119,6 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked, const policy = usePolicy(report?.policyID); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID); - const shouldShowLoadingBar = useLoadingBarVisibility(); const [firstDayFreeTrial] = useOnyx(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL); const [lastDayFreeTrial] = useOnyx(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL); const [accountGuideDetails] = useOnyx(ONYXKEYS.ACCOUNT, {selector: accountGuideDetailsSelector}); @@ -422,7 +420,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked, )} - + {shouldShowEarlyDiscountBanner && ( Date: Thu, 26 Feb 2026 16:19:56 +0100 Subject: [PATCH 5/9] Reuse HeaderLoadingBar in MoneyReportHeader and MoneyRequestHeader to isolate queue re-renders Co-Authored-By: Claude Opus 4.6 (1M context) --- src/{pages/inbox => components}/HeaderLoadingBar.tsx | 2 +- src/components/MoneyReportHeader.tsx | 6 ++---- src/components/MoneyRequestHeader.tsx | 6 ++---- src/pages/inbox/HeaderView.tsx | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) rename src/{pages/inbox => components}/HeaderLoadingBar.tsx (89%) diff --git a/src/pages/inbox/HeaderLoadingBar.tsx b/src/components/HeaderLoadingBar.tsx similarity index 89% rename from src/pages/inbox/HeaderLoadingBar.tsx rename to src/components/HeaderLoadingBar.tsx index 935bf7f51c23..3411c8ce981c 100644 --- a/src/pages/inbox/HeaderLoadingBar.tsx +++ b/src/components/HeaderLoadingBar.tsx @@ -1,6 +1,6 @@ -import LoadingBar from '@components/LoadingBar'; import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import LoadingBar from './LoadingBar'; function HeaderLoadingBar() { const {shouldUseNarrowLayout} = useResponsiveLayout(); diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 0e6b04954ac9..814af4150aea 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -13,7 +13,6 @@ import useDeleteTransactions from '@hooks/useDeleteTransactions'; import useDuplicateTransactionsAndViolations from '@hooks/useDuplicateTransactionsAndViolations'; import useGetIOUReportFromReportAction from '@hooks/useGetIOUReportFromReportAction'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; -import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility'; import useLocalize from '@hooks/useLocalize'; import useMobileSelectionMode from '@hooks/useMobileSelectionMode'; import useNetwork from '@hooks/useNetwork'; @@ -144,13 +143,13 @@ import ConfirmModal from './ConfirmModal'; import DecisionModal from './DecisionModal'; import {useDelegateNoAccessActions, useDelegateNoAccessState} from './DelegateNoAccessModalProvider'; import Header from './Header'; +import HeaderLoadingBar from './HeaderLoadingBar'; import HeaderWithBackButton from './HeaderWithBackButton'; import HoldOrRejectEducationalModal from './HoldOrRejectEducationalModal'; import HoldSubmitterEducationalModal from './HoldSubmitterEducationalModal'; import Icon from './Icon'; import {KYCWallContext} from './KYCWall/KYCWallContext'; import type {PaymentMethod} from './KYCWall/types'; -import LoadingBar from './LoadingBar'; import Modal from './Modal'; import {ModalActions} from './Modal/Global/ModalContext'; import MoneyReportHeaderKYCDropdown from './MoneyReportHeaderKYCDropdown'; @@ -564,7 +563,6 @@ function MoneyReportHeader({ const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES); - const shouldShowLoadingBar = useLoadingBarVisibility(); const kycWallRef = useContext(KYCWallContext); const [betas] = useOnyx(ONYXKEYS.BETAS); const isReportInRHP = route.name !== SCREENS.REPORT; @@ -1900,7 +1898,7 @@ function MoneyReportHeader({ )} - + {isHoldMenuVisible && requestType !== undefined && ( )} - + ) => account?.guideDetails; From 423d69e39c730ff220e6bb68996eb5bd0f04037f Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Thu, 26 Feb 2026 16:41:26 +0100 Subject: [PATCH 6/9] Narrow Network subscriptions in MoneyReportHeader and MoneyRequestHeader with selector Co-Authored-By: Claude Opus 4.6 (1M context) --- src/components/MoneyReportHeader.tsx | 5 +++-- src/components/MoneyRequestHeader.tsx | 5 +++-- src/selectors/Network.ts | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 814af4150aea..d88a890466c6 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -1,5 +1,6 @@ import {useRoute} from '@react-navigation/native'; import {isUserValidatedSelector} from '@selectors/Account'; +import {shouldFailAllRequestsSelector} from '@selectors/Network'; import {hasSeenTourSelector} from '@selectors/Onboarding'; import {getArchiveReason} from '@selectors/Report'; import React, {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react'; @@ -434,7 +435,7 @@ function MoneyReportHeader({ const {removeTransaction, clearSelectedTransactions} = useSearchActionsContext(); const shouldCalculateTotals = useSearchShouldCalculateTotals(currentSearchKey, currentSearchQueryJSON?.hash, true); - const [network] = useOnyx(ONYXKEYS.NETWORK); + const [shouldFailAllRequests] = useOnyx(ONYXKEYS.NETWORK, {selector: shouldFailAllRequestsSelector}); const {isWideRHPDisplayedOnWideLayout, isSuperWideRHPDisplayedOnWideLayout} = useResponsiveLayoutOnWideRHP(); @@ -829,7 +830,7 @@ function MoneyReportHeader({ const dismissModalAndUpdateUseHold = () => { setIsHoldEducationalModalVisible(false); - setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !network?.shouldFailAllRequests); + setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !shouldFailAllRequests); if (requestParentReportAction) { changeMoneyRequestHoldStatus(requestParentReportAction); } diff --git a/src/components/MoneyRequestHeader.tsx b/src/components/MoneyRequestHeader.tsx index 90b641fe9e29..683ddeb56aec 100644 --- a/src/components/MoneyRequestHeader.tsx +++ b/src/components/MoneyRequestHeader.tsx @@ -1,4 +1,5 @@ import {useRoute} from '@react-navigation/native'; +import {shouldFailAllRequestsSelector} from '@selectors/Network'; import {hasSeenTourSelector} from '@selectors/Onboarding'; import type {ReactNode} from 'react'; import React, {useCallback, useMemo, useState} from 'react'; @@ -187,7 +188,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre const shouldOpenParentReportInCurrentTab = !isSelfDM(parentReport); const {wideRHPRouteKeys} = useWideRHPState(); - const [network] = useOnyx(ONYXKEYS.NETWORK); + const [shouldFailAllRequests] = useOnyx(ONYXKEYS.NETWORK, {selector: shouldFailAllRequestsSelector}); const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE); const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); const [betas] = useOnyx(ONYXKEYS.BETAS); @@ -385,7 +386,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre const dismissModalAndUpdateUseHold = () => { setIsHoldEducationalModalVisible(false); - setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !network?.shouldFailAllRequests); + setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !shouldFailAllRequests); if (parentReportAction) { changeMoneyRequestHoldStatus(parentReportAction); } diff --git a/src/selectors/Network.ts b/src/selectors/Network.ts index 457776a81a37..011a7ffce75a 100644 --- a/src/selectors/Network.ts +++ b/src/selectors/Network.ts @@ -14,5 +14,6 @@ const networkStatusSelector = (networkData: OnyxEntry) => { }; }; -// eslint-disable-next-line import/prefer-default-export -export {networkStatusSelector}; +const shouldFailAllRequestsSelector = (network: OnyxEntry) => !!network?.shouldFailAllRequests; + +export {networkStatusSelector, shouldFailAllRequestsSelector}; From 0cc622e30cbd62340894d5430f049e1cad070ff4 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Thu, 26 Feb 2026 17:35:45 +0100 Subject: [PATCH 7/9] Fix canEvict error in useParentReportAction when parentReportID is undefined --- src/hooks/useParentReportAction.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hooks/useParentReportAction.ts b/src/hooks/useParentReportAction.ts index 2094bf4f8dce..3f512c3219e8 100644 --- a/src/hooks/useParentReportAction.ts +++ b/src/hooks/useParentReportAction.ts @@ -12,10 +12,14 @@ function useParentReportAction(report: OnyxEntry) { [report?.parentReportActionID], ); + const parentReportID = getNonEmptyStringOnyxID(report?.parentReportID); + const [parentReportAction] = useOnyx( - `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(report?.parentReportID)}`, + `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, { - canEvict: false, + // Only set canEvict when we have a valid parentReportID — reportActions_ is an evictable key, + // but reportActions_undefined is not and will throw if canEvict is specified. + canEvict: parentReportID ? false : undefined, selector: getParentReportAction, }, From 9759d7e655e2e7f38ef3f86b0c30f05b97dd92b9 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Fri, 27 Feb 2026 14:42:24 +0100 Subject: [PATCH 8/9] Move HeaderView selectors to dedicated files and add unit tests Move accountGuideDetailsSelector to Account.ts and reportMetadataSelector (renamed to pendingChatMembersSelector) to ReportMetaData.ts. Add unit tests for all new selectors including Network selectors. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/pages/inbox/HeaderView.tsx | 11 ++-- src/selectors/Account.ts | 3 ++ src/selectors/ReportMetaData.ts | 5 +- tests/unit/selectors/AccountTest.ts | 19 ++++++- tests/unit/selectors/NetworkTest.ts | 56 +++++++++++++++++++ tests/unit/selectors/ReportMetaDataTest.ts | 62 ++++++++++++++++++++++ 6 files changed, 147 insertions(+), 9 deletions(-) create mode 100644 tests/unit/selectors/NetworkTest.ts create mode 100644 tests/unit/selectors/ReportMetaDataTest.ts diff --git a/src/pages/inbox/HeaderView.tsx b/src/pages/inbox/HeaderView.tsx index 6592078c5582..759e6e41d168 100644 --- a/src/pages/inbox/HeaderView.tsx +++ b/src/pages/inbox/HeaderView.tsx @@ -1,4 +1,6 @@ import {useRoute} from '@react-navigation/native'; +import {accountGuideDetailsSelector} from '@selectors/Account'; +import {pendingChatMembersSelector} from '@selectors/ReportMetaData'; import {isPast} from 'date-fns'; import React, {useMemo} from 'react'; import {View} from 'react-native'; @@ -79,14 +81,9 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import SCREENS from '@src/SCREENS'; import reportsSelector from '@src/selectors/Attributes'; -import type {Account, Report, ReportAction, ReportMetadata} from '@src/types/onyx'; +import type {Report, ReportAction} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -const accountGuideDetailsSelector = (account: OnyxEntry) => account?.guideDetails; - -const reportMetadataSelector = (reportMetadata: OnyxEntry): OnyxEntry => - reportMetadata ? {pendingChatMembers: reportMetadata.pendingChatMembers} : undefined; - type HeaderViewProps = { /** Toggles the navigationMenu open and closed */ onNavigationMenuButtonClicked: () => void; @@ -122,7 +119,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked, const [lastDayFreeTrial] = useOnyx(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL); const [accountGuideDetails] = useOnyx(ONYXKEYS.ACCOUNT, {selector: accountGuideDetailsSelector}); const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`); - const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`, {selector: reportMetadataSelector}); + const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`, {selector: pendingChatMembersSelector}); const isReportArchived = isArchivedReport(reportNameValuePairs); const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {selector: reportsSelector}); diff --git a/src/selectors/Account.ts b/src/selectors/Account.ts index eccadd18e032..808a83a1a015 100644 --- a/src/selectors/Account.ts +++ b/src/selectors/Account.ts @@ -15,6 +15,8 @@ const isAccountLoadingSelector = (data: OnyxEntry) => !!data?.isLoading const requiresTwoFactorAuthSelector = (data: OnyxEntry) => data?.requiresTwoFactorAuth; +const accountGuideDetailsSelector = (account: OnyxEntry) => account?.guideDetails; + export { isActingAsDelegateSelector, isUserValidatedSelector, @@ -23,4 +25,5 @@ export { hasBiometricsRegisteredSelector, isAccountLoadingSelector, requiresTwoFactorAuthSelector, + accountGuideDetailsSelector, }; diff --git a/src/selectors/ReportMetaData.ts b/src/selectors/ReportMetaData.ts index b762ac72ef67..723f6d13ebbb 100644 --- a/src/selectors/ReportMetaData.ts +++ b/src/selectors/ReportMetaData.ts @@ -5,4 +5,7 @@ const isActionLoadingSelector = (reportMetadata: OnyxEntry) => r const hasOnceLoadedReportActionsSelector = (reportMetadata: OnyxEntry) => reportMetadata?.hasOnceLoadedReportActions; -export {isActionLoadingSelector, hasOnceLoadedReportActionsSelector}; +const pendingChatMembersSelector = (reportMetadata: OnyxEntry): OnyxEntry => + reportMetadata ? {pendingChatMembers: reportMetadata.pendingChatMembers} : undefined; + +export {isActionLoadingSelector, hasOnceLoadedReportActionsSelector, pendingChatMembersSelector}; diff --git a/tests/unit/selectors/AccountTest.ts b/tests/unit/selectors/AccountTest.ts index a88fa6f6ce61..54922c07c782 100644 --- a/tests/unit/selectors/AccountTest.ts +++ b/tests/unit/selectors/AccountTest.ts @@ -1,7 +1,24 @@ -import {requiresTwoFactorAuthSelector} from '@selectors/Account'; +import {accountGuideDetailsSelector, requiresTwoFactorAuthSelector} from '@selectors/Account'; import type {OnyxEntry} from 'react-native-onyx'; import type {Account} from '@src/types/onyx'; +describe('accountGuideDetailsSelector', () => { + it('returns guideDetails when present', () => { + const guideDetails = {email: 'guide@expensify.com', calendarLink: 'https://calendly.com/guide'}; + const account: OnyxEntry = {guideDetails}; + expect(accountGuideDetailsSelector(account)).toEqual(guideDetails); + }); + + it('returns undefined when guideDetails is not set', () => { + const account: OnyxEntry = {}; + expect(accountGuideDetailsSelector(account)).toBeUndefined(); + }); + + it('returns undefined when account is undefined', () => { + expect(accountGuideDetailsSelector(undefined)).toBeUndefined(); + }); +}); + describe('requiresTwoFactorAuthSelector', () => { it('returns true when requiresTwoFactorAuth is true', () => { const account: OnyxEntry = {requiresTwoFactorAuth: true}; diff --git a/tests/unit/selectors/NetworkTest.ts b/tests/unit/selectors/NetworkTest.ts new file mode 100644 index 000000000000..06acf9ec4876 --- /dev/null +++ b/tests/unit/selectors/NetworkTest.ts @@ -0,0 +1,56 @@ +import {networkStatusSelector, shouldFailAllRequestsSelector} from '@selectors/Network'; +import type {OnyxEntry} from 'react-native-onyx'; +import CONST from '@src/CONST'; +import type {Network} from '@src/types/onyx'; + +describe('shouldFailAllRequestsSelector', () => { + it('returns true when shouldFailAllRequests is true', () => { + const network: OnyxEntry = {isOffline: false, shouldFailAllRequests: true}; + expect(shouldFailAllRequestsSelector(network)).toBe(true); + }); + + it('returns false when shouldFailAllRequests is false', () => { + const network: OnyxEntry = {isOffline: false, shouldFailAllRequests: false}; + expect(shouldFailAllRequestsSelector(network)).toBe(false); + }); + + it('returns false when shouldFailAllRequests is not set', () => { + const network: OnyxEntry = {isOffline: false}; + expect(shouldFailAllRequestsSelector(network)).toBe(false); + }); + + it('returns false when network is undefined', () => { + expect(shouldFailAllRequestsSelector(undefined)).toBe(false); + }); +}); + +describe('networkStatusSelector', () => { + it('returns network status fields when network data is provided', () => { + const network: OnyxEntry = { + isOffline: true, + networkStatus: CONST.NETWORK.NETWORK_STATUS.OFFLINE, + lastOfflineAt: '2024-01-01T00:00:00Z', + }; + expect(networkStatusSelector(network)).toEqual({ + isOffline: true, + networkStatus: CONST.NETWORK.NETWORK_STATUS.OFFLINE, + lastOfflineAt: '2024-01-01T00:00:00Z', + }); + }); + + it('returns default data with UNKNOWN status when network is undefined', () => { + expect(networkStatusSelector(undefined)).toEqual({ + ...CONST.DEFAULT_NETWORK_DATA, + networkStatus: CONST.NETWORK.NETWORK_STATUS.UNKNOWN, + }); + }); + + it('returns undefined for optional fields when not set', () => { + const network: OnyxEntry = {isOffline: false}; + expect(networkStatusSelector(network)).toEqual({ + isOffline: false, + networkStatus: undefined, + lastOfflineAt: undefined, + }); + }); +}); diff --git a/tests/unit/selectors/ReportMetaDataTest.ts b/tests/unit/selectors/ReportMetaDataTest.ts new file mode 100644 index 000000000000..dc2a9d130223 --- /dev/null +++ b/tests/unit/selectors/ReportMetaDataTest.ts @@ -0,0 +1,62 @@ +import {hasOnceLoadedReportActionsSelector, isActionLoadingSelector, pendingChatMembersSelector} from '@selectors/ReportMetaData'; +import type {OnyxEntry} from 'react-native-onyx'; +import type {ReportMetadata} from '@src/types/onyx'; + +describe('isActionLoadingSelector', () => { + it('returns true when isActionLoading is true', () => { + const reportMetadata: OnyxEntry = {isActionLoading: true}; + expect(isActionLoadingSelector(reportMetadata)).toBe(true); + }); + + it('returns false when isActionLoading is false', () => { + const reportMetadata: OnyxEntry = {isActionLoading: false}; + expect(isActionLoadingSelector(reportMetadata)).toBe(false); + }); + + it('returns false when isActionLoading is not set', () => { + const reportMetadata: OnyxEntry = {}; + expect(isActionLoadingSelector(reportMetadata)).toBe(false); + }); + + it('returns false when reportMetadata is undefined', () => { + expect(isActionLoadingSelector(undefined)).toBe(false); + }); +}); + +describe('hasOnceLoadedReportActionsSelector', () => { + it('returns true when hasOnceLoadedReportActions is true', () => { + const reportMetadata: OnyxEntry = {hasOnceLoadedReportActions: true}; + expect(hasOnceLoadedReportActionsSelector(reportMetadata)).toBe(true); + }); + + it('returns false when hasOnceLoadedReportActions is false', () => { + const reportMetadata: OnyxEntry = {hasOnceLoadedReportActions: false}; + expect(hasOnceLoadedReportActionsSelector(reportMetadata)).toBe(false); + }); + + it('returns undefined when hasOnceLoadedReportActions is not set', () => { + const reportMetadata: OnyxEntry = {}; + expect(hasOnceLoadedReportActionsSelector(reportMetadata)).toBeUndefined(); + }); + + it('returns undefined when reportMetadata is undefined', () => { + expect(hasOnceLoadedReportActionsSelector(undefined)).toBeUndefined(); + }); +}); + +describe('pendingChatMembersSelector', () => { + it('returns object with pendingChatMembers when present', () => { + const pendingChatMembers = [{accountID: '12345', pendingAction: 'add' as const}]; + const reportMetadata: OnyxEntry = {pendingChatMembers}; + expect(pendingChatMembersSelector(reportMetadata)).toEqual({pendingChatMembers}); + }); + + it('returns object with undefined pendingChatMembers when field is not set', () => { + const reportMetadata: OnyxEntry = {}; + expect(pendingChatMembersSelector(reportMetadata)).toEqual({pendingChatMembers: undefined}); + }); + + it('returns undefined when reportMetadata is undefined', () => { + expect(pendingChatMembersSelector(undefined)).toBeUndefined(); + }); +}); From 66bf420b95c7ab72bfe70acfee57349ebf3089ee Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Fri, 27 Feb 2026 14:43:10 +0100 Subject: [PATCH 9/9] add missing react import --- src/components/HeaderLoadingBar.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/HeaderLoadingBar.tsx b/src/components/HeaderLoadingBar.tsx index 3411c8ce981c..8761aba6fc67 100644 --- a/src/components/HeaderLoadingBar.tsx +++ b/src/components/HeaderLoadingBar.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import LoadingBar from './LoadingBar';