Skip to content

Commit 28a2b2c

Browse files
rhamiltoclaude
andcommitted
fix(BulkSelect): call label functions inside useMemo for better performance
Moved label function calls inside useMemo to avoid calling them on every render. This is especially important for pseudolocalization where label functions may be expensive. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 5935d2c commit 28a2b2c

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

packages/module/src/BulkSelect/BulkSelect.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ export const BulkSelect: FC<BulkSelectProps> = ({
8585
}: BulkSelectProps) => {
8686
const [ isOpen, setOpen ] = useState(false);
8787

88-
// Compute label text to use as memo dependencies for i18n support
89-
const selectPageLabelText = selectPageLabel(pageCount);
90-
const selectAllLabelText = selectAllLabel(totalCount);
91-
const selectedLabelText = selectedLabel(selectedCount);
92-
9388
const splitButtonDropdownItems = useMemo(
9489
() => (
9590
<>
@@ -98,19 +93,21 @@ export const BulkSelect: FC<BulkSelectProps> = ({
9893
</DropdownItem>
9994
{isDataPaginated && (
10095
<DropdownItem ouiaId={`${ouiaId}-select-page`} value={BulkSelectValue.page} key={BulkSelectValue.page}>
101-
{selectPageLabelText}
96+
{selectPageLabel(pageCount)}
10297
</DropdownItem>
10398
)}
10499
{canSelectAll && (
105100
<DropdownItem ouiaId={`${ouiaId}-select-all`} value={BulkSelectValue.all} key={BulkSelectValue.all}>
106-
{selectAllLabelText}
101+
{selectAllLabel(totalCount)}
107102
</DropdownItem>
108103
)}
109104
</>
110105
),
111-
[ isDataPaginated, canSelectAll, ouiaId, selectNoneLabel, selectPageLabelText, selectAllLabelText ]
106+
[ isDataPaginated, canSelectAll, ouiaId, selectNoneLabel, selectPageLabel, selectAllLabel, pageCount, totalCount ]
112107
);
113108

109+
const selectedLabelText = selectedLabel(selectedCount);
110+
114111
const allOption = isDataPaginated ? BulkSelectValue.page : BulkSelectValue.all;
115112
const noneOption = isDataPaginated ? BulkSelectValue.nonePage : BulkSelectValue.none;
116113

0 commit comments

Comments
 (0)