Skip to content

Commit

Permalink
getInsertionPoint: Avoid returning a different object on every call (#…
Browse files Browse the repository at this point in the history
…53722)

* getInsertionPoint: Avoid returning a different object on every call
* Use consistent return type
  • Loading branch information
Mamaduka authored Aug 16, 2023
1 parent 3ac37ea commit fb9e8ce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
12 changes: 10 additions & 2 deletions packages/customize-widgets/src/store/selectors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const EMPTY_INSERTION_POINT = {
rootClientId: undefined,
insertionIndex: undefined,
};

/**
* Returns true if the inserter is opened.
*
Expand Down Expand Up @@ -35,6 +40,9 @@ 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 };
if ( typeof state === 'boolean' ) {
return EMPTY_INSERTION_POINT;
}

return state.blockInserterPanel;
}
13 changes: 10 additions & 3 deletions packages/edit-post/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -472,9 +477,11 @@ 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 };
if ( typeof state === 'boolean' ) {
return EMPTY_INSERTION_POINT;
}

return state.blockInserterPanel;
}

/**
Expand Down
12 changes: 10 additions & 2 deletions packages/edit-widgets/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -254,8 +259,11 @@ 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 };
if ( typeof state === 'boolean' ) {
return EMPTY_INSERTION_POINT;
}

return state.blockInserterPanel;
}

/**
Expand Down

1 comment on commit fb9e8ce

@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 fb9e8ce.
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/5878975169
📝 Reported issues:

Please sign in to comment.