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 Feb 27, 2023
1 parent d116f9f commit 98ddd92
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 @@ -117,6 +118,9 @@ export default function BorderPanel( { name, variation = '' } ) {
`${ prefix }border.radius`,
name
);

const debouncedSetBorderRadius = debounce( setBorderRadius, 5 );

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

0 comments on commit 98ddd92

Please sign in to comment.