Skip to content

Commit

Permalink
Add debounce to border radius update in global styles to improve perf…
Browse files Browse the repository at this point in the history
…ormance
  • Loading branch information
glendaviesnz committed Jan 29, 2023
1 parent b97255d commit 872d53c
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@wordpress/components';
import { useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { debounce } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -119,6 +120,9 @@ export default function BorderPanel( { name, variationPath = '' } ) {
`${ variationPath }border.radius`,
name
);

const debouncedSetBorderRadius = debounce( setBorderRadius, 5 );

const hasBorderRadius = () => {
const borderValues = userBorderStyles?.radius;
if ( typeof borderValues === 'object' ) {
Expand Down Expand Up @@ -207,7 +211,7 @@ export default function BorderPanel( { name, variationPath = '' } ) {
<BorderRadiusControl
values={ borderRadiusValues }
onChange={ ( value ) => {
setBorderRadius( value || undefined );
debouncedSetBorderRadius( value || undefined );
} }
/>
</ToolsPanelItem>
Expand Down

0 comments on commit 872d53c

Please sign in to comment.