Skip to content

Commit

Permalink
Editor: Memoize 'getInsertionPoint' selector (#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 committed Mar 22, 2024
1 parent e7ad4b5 commit 8e1a7bc
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

1 comment on commit 8e1a7bc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 8e1a7bc.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8386925839
📝 Reported issues:

Please sign in to comment.