Skip to content

Commit

Permalink
Editor: Memoize 'getInsertionPoint' selector (WordPress#60015)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
  • Loading branch information
3 people authored and carstingaxion committed Mar 27, 2024
1 parent db6c9d0 commit 1b7804e
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions packages/editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import createSelector from 'rememo';

/**
* WordPress dependencies
*/
Expand All @@ -22,28 +27,41 @@ const EMPTY_INSERTION_POINT = {
*
* @return {Object} The root client ID, index to insert at and starting filter value.
*/
export const getInsertionPoint = createRegistrySelector(
( select ) => ( state ) => {
if ( typeof state.blockInserterPanel === 'object' ) {
return state.blockInserterPanel;
}
export const getInsertionPoint = createRegistrySelector( ( select ) =>
createSelector(
( state ) => {
if ( typeof state.blockInserterPanel === 'object' ) {
return state.blockInserterPanel;
}

if ( getRenderingMode( state ) === 'template-locked' ) {
if ( getRenderingMode( state ) === 'template-locked' ) {
const [ postContentClientId ] =
select( blockEditorStore ).getBlocksByName(
'core/post-content'
);
if ( postContentClientId ) {
return {
rootClientId: postContentClientId,
insertionIndex: undefined,
filterValue: undefined,
};
}
}

return EMPTY_INSERTION_POINT;
},
( state ) => {
const [ postContentClientId ] =
select( blockEditorStore ).getBlocksByName(
'core/post-content'
);
if ( postContentClientId ) {
return {
rootClientId: postContentClientId,
insertionIndex: undefined,
filterValue: undefined,
};
}
return [
state.blockInserterPanel,
getRenderingMode( state ),
postContentClientId,
];
}

return EMPTY_INSERTION_POINT;
}
)
);

export function getListViewToggleRef( state ) {
Expand Down

0 comments on commit 1b7804e

Please sign in to comment.