From b2e886b97a18857ed868fdaeac4fa890190ed03c Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 15 Aug 2023 17:50:53 +0400 Subject: [PATCH 1/2] getInsertionPoint: Avoid returning a different object on every call --- packages/customize-widgets/src/store/selectors.js | 3 +-- packages/edit-post/src/store/selectors.js | 4 +--- packages/edit-widgets/src/store/selectors.js | 3 +-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/customize-widgets/src/store/selectors.js b/packages/customize-widgets/src/store/selectors.js index abe2cb89c9f6ab..b9de29320857ae 100644 --- a/packages/customize-widgets/src/store/selectors.js +++ b/packages/customize-widgets/src/store/selectors.js @@ -35,6 +35,5 @@ export function isInserterOpened( state ) { * @return {Object} The root client ID and index to insert at. */ export function __experimentalGetInsertionPoint( state ) { - const { rootClientId, insertionIndex } = state.blockInserterPanel; - return { rootClientId, insertionIndex }; + return state.blockInserterPanel; } diff --git a/packages/edit-post/src/store/selectors.js b/packages/edit-post/src/store/selectors.js index 5ae7d6b4437b71..482f7eb236571c 100644 --- a/packages/edit-post/src/store/selectors.js +++ b/packages/edit-post/src/store/selectors.js @@ -472,9 +472,7 @@ export function isInserterOpened( state ) { * @return {Object} The root client ID, index to insert at and starting filter value. */ export function __experimentalGetInsertionPoint( state ) { - const { rootClientId, insertionIndex, filterValue } = - state.blockInserterPanel; - return { rootClientId, insertionIndex, filterValue }; + return state.blockInserterPanel; } /** diff --git a/packages/edit-widgets/src/store/selectors.js b/packages/edit-widgets/src/store/selectors.js index 80bcddfead7b3f..6126b132b35842 100644 --- a/packages/edit-widgets/src/store/selectors.js +++ b/packages/edit-widgets/src/store/selectors.js @@ -254,8 +254,7 @@ export function isInserterOpened( state ) { * @return {Object} The root client ID and index to insert at. */ export function __experimentalGetInsertionPoint( state ) { - const { rootClientId, insertionIndex } = state.blockInserterPanel; - return { rootClientId, insertionIndex }; + return state.blockInserterPanel; } /** From 139d7a8e9a0dc366f8c6da9fe39332b6d8277296 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 16 Aug 2023 16:16:00 +0400 Subject: [PATCH 2/2] Use consistent return type --- packages/customize-widgets/src/store/selectors.js | 9 +++++++++ packages/edit-post/src/store/selectors.js | 9 +++++++++ packages/edit-widgets/src/store/selectors.js | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/packages/customize-widgets/src/store/selectors.js b/packages/customize-widgets/src/store/selectors.js index b9de29320857ae..b62f7ec1d8709b 100644 --- a/packages/customize-widgets/src/store/selectors.js +++ b/packages/customize-widgets/src/store/selectors.js @@ -1,3 +1,8 @@ +const EMPTY_INSERTION_POINT = { + rootClientId: undefined, + insertionIndex: undefined, +}; + /** * Returns true if the inserter is opened. * @@ -35,5 +40,9 @@ export function isInserterOpened( state ) { * @return {Object} The root client ID and index to insert at. */ export function __experimentalGetInsertionPoint( state ) { + if ( typeof state === 'boolean' ) { + return EMPTY_INSERTION_POINT; + } + return state.blockInserterPanel; } diff --git a/packages/edit-post/src/store/selectors.js b/packages/edit-post/src/store/selectors.js index 482f7eb236571c..a30bcc188b4966 100644 --- a/packages/edit-post/src/store/selectors.js +++ b/packages/edit-post/src/store/selectors.js @@ -15,6 +15,11 @@ import deprecated from '@wordpress/deprecated'; const EMPTY_ARRAY = []; const EMPTY_OBJECT = {}; +const EMPTY_INSERTION_POINT = { + rootClientId: undefined, + insertionIndex: undefined, + filterValue: undefined, +}; /** * Returns the current editing mode. @@ -472,6 +477,10 @@ export function isInserterOpened( state ) { * @return {Object} The root client ID, index to insert at and starting filter value. */ export function __experimentalGetInsertionPoint( state ) { + if ( typeof state === 'boolean' ) { + return EMPTY_INSERTION_POINT; + } + return state.blockInserterPanel; } diff --git a/packages/edit-widgets/src/store/selectors.js b/packages/edit-widgets/src/store/selectors.js index 6126b132b35842..63f33475eb3c53 100644 --- a/packages/edit-widgets/src/store/selectors.js +++ b/packages/edit-widgets/src/store/selectors.js @@ -19,6 +19,11 @@ import { } from './utils'; import { STORE_NAME as editWidgetsStoreName } from './constants'; +const EMPTY_INSERTION_POINT = { + rootClientId: undefined, + insertionIndex: undefined, +}; + /** * Returns all API widgets. * @@ -254,6 +259,10 @@ export function isInserterOpened( state ) { * @return {Object} The root client ID and index to insert at. */ export function __experimentalGetInsertionPoint( state ) { + if ( typeof state === 'boolean' ) { + return EMPTY_INSERTION_POINT; + } + return state.blockInserterPanel; }