Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 9 additions & 15 deletions src/components/SelectionScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ type SelectionScreenProps<T = string> = {
/** Whether to show the text input */
shouldShowTextInput?: boolean;

/** Label for the text input */
textInputLabel?: string;
textInputOptions?: {
/** Label for the text input */
label?: string;

/** Value for the text input */
textInputValue?: string;
/** Value for the text input */
value?: string;

/** Callback to fire when the text input changes */
onChangeText?: (text: string) => void;
/** Callback to fire when the text input changes */
onChangeText?: (text: string) => void;
};
};

function SelectionScreen<T = string>({
Expand All @@ -135,10 +137,8 @@ function SelectionScreen<T = string>({
onClose,
shouldSingleExecuteRowSelect,
headerTitleAlreadyTranslated,
textInputLabel,
textInputValue,
onChangeText,
shouldShowTextInput,
textInputOptions,
shouldUpdateFocusedIndex = false,
}: SelectionScreenProps<T>) {
const {translate} = useLocalize();
Expand All @@ -147,12 +147,6 @@ function SelectionScreen<T = string>({
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: false});
const isConnectionEmpty = isEmpty(policy?.connections?.[connectionName]);

const textInputOptions = {
onChangeText,
textInputLabel,
textInputValue,
};

return (
<AccessOrNotFoundWrapper
policyID={policyID}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useMemo, useState} from 'react';
import React, {useMemo, useState} from 'react';
import {View} from 'react-native';
import BlockingView from '@components/BlockingViews/BlockingView';
import RenderHTML from '@components/RenderHTML';
Expand Down Expand Up @@ -60,33 +60,27 @@ function WorkspaceCompanyCardAccountSelectCardPage({route}: WorkspaceCompanyCard
return tokenizedSearch(exportMenuItem?.data ?? [], searchText, (option) => [option.value]);
}, [exportMenuItem?.data, searchText]);

const listEmptyContent = useMemo(
() => (
<BlockingView
icon={illustrations.Telescope}
iconWidth={variables.emptyListIconWidth}
iconHeight={variables.emptyListIconHeight}
title={translate('workspace.moreFeatures.companyCards.noAccountsFound')}
subtitle={currentConnectionName ? translate('workspace.moreFeatures.companyCards.noAccountsFoundDescription', currentConnectionName) : undefined}
containerStyle={styles.pb10}
/>
),
[translate, currentConnectionName, styles, illustrations.Telescope],
const listEmptyContent = (

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.

❌ PERF-4 (docs)

The listEmptyContent JSX element should remain memoized with useMemo. Since WorkspaceCompanyCardAccountSelectCardPage is not optimized by React Compiler and SelectionScreen is optimized, creating a new JSX element reference on every render prevents React from skipping re-renders of SelectionScreen.

Suggested fix:

Revert this change and keep the useMemo wrapper:

const listEmptyContent = useMemo(
    () => (
        <BlockingView
            icon={illustrations.Telescope}
            iconWidth={variables.emptyListIconWidth}
            iconHeight={variables.emptyListIconHeight}
            title={translate('workspace.moreFeatures.companyCards.noAccountsFound')}
            subtitle={currentConnectionName ? translate('workspace.moreFeatures.companyCards.noAccountsFoundDescription', currentConnectionName) : undefined}
            containerStyle={styles.pb10}
        />
    ),
    [translate, currentConnectionName, styles, illustrations.Telescope],
);

<BlockingView
icon={illustrations.Telescope}
iconWidth={variables.emptyListIconWidth}
iconHeight={variables.emptyListIconHeight}
title={translate('workspace.moreFeatures.companyCards.noAccountsFound')}
subtitle={currentConnectionName ? translate('workspace.moreFeatures.companyCards.noAccountsFoundDescription', currentConnectionName) : undefined}
containerStyle={styles.pb10}
/>
);

const updateExportAccount = useCallback(
({value}: SelectorType) => {
if (!exportMenuItem?.exportType) {
return;
}
const isDefaultSelected = value === defaultCard || value === defaultVendor;
const exportValue = isDefaultSelected ? CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE : value;
setCompanyCardExportAccount(policyID, domainOrWorkspaceAccountID, cardID, exportMenuItem.exportType, exportValue, getCompanyCardFeed(feed));
const updateExportAccount = ({value}: SelectorType) => {

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.

❌ PERF-4 (docs)

The updateExportAccount function should remain wrapped in useCallback. Since WorkspaceCompanyCardAccountSelectCardPage is not optimized by React Compiler and SelectionScreen is optimized, creating a new function reference on every render prevents React from skipping re-renders of SelectionScreen.

Suggested fix:

Revert this change and keep the useCallback wrapper:

const updateExportAccount = useCallback(
    ({value}: SelectorType) => {
        if (\!exportMenuItem?.exportType) {
            return;
        }
        const isDefaultSelected = value === defaultCard || value === defaultVendor;
        const exportValue = isDefaultSelected ? CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE : value;
        setCompanyCardExportAccount(policyID, domainOrWorkspaceAccountID, cardID, exportMenuItem.exportType, exportValue, getCompanyCardFeed(feed));

        Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARD_DETAILS.getRoute(policyID, feed, cardID, backTo));
    },
    [exportMenuItem?.exportType, domainOrWorkspaceAccountID, cardID, policyID, feed, defaultCard, defaultVendor, backTo],
);

if (!exportMenuItem?.exportType) {
return;
}
const isDefaultSelected = value === defaultCard || value === defaultVendor;
const exportValue = isDefaultSelected ? CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE : value;
setCompanyCardExportAccount(policyID, domainOrWorkspaceAccountID, cardID, exportMenuItem.exportType, exportValue, getCompanyCardFeed(feed));

Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARD_DETAILS.getRoute(policyID, feed, cardID, backTo));
},
[exportMenuItem?.exportType, domainOrWorkspaceAccountID, cardID, policyID, feed, defaultCard, defaultVendor, backTo],
);
Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARD_DETAILS.getRoute(policyID, feed, cardID, backTo));
};

return (
<SelectionScreen
Expand All @@ -113,9 +107,11 @@ function WorkspaceCompanyCardAccountSelectCardPage({route}: WorkspaceCompanyCard
displayName="WorkspaceCompanyCardAccountSelectCardPage"
data={searchedListOptions ?? []}
listItem={RadioListItem}
textInputLabel={translate('common.search')}
textInputValue={searchText}
onChangeText={setSearchText}
textInputOptions={{

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.

❌ PERF-4 (docs)

The textInputOptions object is created inline on every render. Since WorkspaceCompanyCardAccountSelectCardPage is not optimized by React Compiler and SelectionScreen is optimized, this new object reference prevents React from skipping re-renders of SelectionScreen.

Suggested fix:

const textInputOptions = useMemo(
    () => ({
        label: translate('common.search'),
        value: searchText,
        onChangeText: setSearchText,
    }),
    [translate, searchText],
);

label: translate('common.search'),
value: searchText,
onChangeText: setSearchText,
}}
onSelectRow={updateExportAccount}
initiallyFocusedOptionKey={exportMenuItem?.data?.find((mode) => mode.isSelected)?.keyForList}
onBackButtonPress={() => Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARD_DETAILS.getRoute(policyID, feed, cardID, backTo))}
Expand Down
Loading