Product Block Editor: fix performance issue when rendering thousands of attributes in the attributes modal (#47638)

* define select deps to avoid re-renders

* chnagelog

* define sort criteria out of the cmp scope
This commit is contained in:
Damián Suárez 2024-05-21 10:14:41 +01:00 committed by GitHub
parent 5168a21920
commit 64b8c680fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Product Block Editor: fix perfomance issue when rendering thousands of attributes in the attributes modal

View File

@ -57,6 +57,11 @@ type AttributeForm = {
attributes: Array< EnhancedProductAttribute | null >;
};
/*
* Sort criteria for the attributes.
*/
const attributeSortCriteria = { order_by: 'name' };
export const NewAttributeModal: React.FC< NewAttributeModalProps > = ( {
title = __( 'Add attributes', 'woocommerce' ),
description = '',
@ -193,8 +198,6 @@ export const NewAttributeModal: React.FC< NewAttributeModalProps > = ( {
name: defaultSearch,
} as EnhancedProductAttribute;
const attributeSortCriteria = { order_by: 'name' };
const { attributes, isLoadingAttributes } = useSelect(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
@ -211,7 +214,8 @@ export const NewAttributeModal: React.FC< NewAttributeModalProps > = ( {
),
attributes: getAttributes( attributeSortCriteria ),
};
}
},
[]
);
const { createErrorNotice } = useDispatch( 'core/notices' );