Skip to content

Commit

Permalink
Inner blocks: memoize allowedBlocks to prevent needlessly updating se…
Browse files Browse the repository at this point in the history
…ttings (#30311)
  • Loading branch information
ellatrix authored Mar 30, 2021
1 parent 12c2326 commit 2c445b1
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useLayoutEffect } from '@wordpress/element';
import { useLayoutEffect, useMemo } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import isShallowEqual from '@wordpress/is-shallow-equal';

Expand Down Expand Up @@ -54,9 +54,13 @@ export default function useNestedSettingsUpdate(
[ clientId ]
);

// Memoize as inner blocks implementors often pass a new array on every
// render.
const _allowedBlocks = useMemo( () => allowedBlocks, allowedBlocks );

useLayoutEffect( () => {
const newSettings = {
allowedBlocks,
allowedBlocks: _allowedBlocks,
templateLock:
templateLock === undefined ? parentLock : templateLock,
};
Expand All @@ -77,7 +81,7 @@ export default function useNestedSettingsUpdate(
}, [
clientId,
blockListSettings,
allowedBlocks,
_allowedBlocks,
templateLock,
parentLock,
captureToolbars,
Expand Down

0 comments on commit 2c445b1

Please sign in to comment.