Skip to content

Commit e57eed5

Browse files
Mamadukaellatrixtyxla
authored
Inserter: Return the same items when the state and parameters don't change (#62263)
* Inserter: Return the same items when the state and parameters don't change * Use stable default Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
1 parent 329369b commit e57eed5

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/block-editor/src/components/inserter/hooks/use-block-types-state.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
parse,
99
} from '@wordpress/blocks';
1010
import { useSelect } from '@wordpress/data';
11-
import { useCallback } from '@wordpress/element';
11+
import { useCallback, useMemo } from '@wordpress/element';
1212

1313
/**
1414
* Internal dependencies
@@ -25,13 +25,18 @@ import { withRootClientIdOptionKey } from '../../../store/utils';
2525
* @return {Array} Returns the block types state. (block types, categories, collections, onSelect handler)
2626
*/
2727
const useBlockTypesState = ( rootClientId, onInsert, isQuick ) => {
28+
const options = useMemo(
29+
() => ( { [ withRootClientIdOptionKey ]: ! isQuick } ),
30+
[ isQuick ]
31+
);
2832
const [ items ] = useSelect(
2933
( select ) => [
30-
select( blockEditorStore ).getInserterItems( rootClientId, {
31-
[ withRootClientIdOptionKey ]: ! isQuick,
32-
} ),
34+
select( blockEditorStore ).getInserterItems(
35+
rootClientId,
36+
options
37+
),
3338
],
34-
[ rootClientId, isQuick ]
39+
[ rootClientId, options ]
3540
);
3641

3742
const [ categories, collections ] = useSelect( ( select ) => {

packages/block-editor/src/store/selectors.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ const EMPTY_ARRAY = [];
7676
*/
7777
const EMPTY_SET = new Set();
7878

79+
const EMPTY_OBJECT = {};
80+
7981
/**
8082
* Returns a block's name given its client ID, or null if no block exists with
8183
* the client ID.
@@ -1996,7 +1998,7 @@ const buildBlockTypeItem =
19961998
*/
19971999
export const getInserterItems = createRegistrySelector( ( select ) =>
19982000
createSelector(
1999-
( state, rootClientId = null, options = {} ) => {
2001+
( state, rootClientId = null, options = EMPTY_OBJECT ) => {
20002002
const buildReusableBlockInserterItem = ( reusableBlock ) => {
20012003
const icon = ! reusableBlock.wp_pattern_sync_status
20022004
? {

0 commit comments

Comments
 (0)