Skip to content

Commit

Permalink
Avoid using a memoized selector without dependencies (#57257)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Jan 1, 2024
1 parent 4eb3b74 commit 18dd101
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
19 changes: 3 additions & 16 deletions packages/edit-widgets/src/store/private-selectors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
/**
* External dependencies
*/
import createSelector from 'rememo';

/**
* WordPress dependencies
*/
import { createRef } from '@wordpress/element';

export const getListViewToggleRef = createSelector(
() => {
return createRef();
},
() => []
);
export function getListViewToggleRef( state ) {
return state.listViewToggleRef;
}
11 changes: 11 additions & 0 deletions packages/edit-widgets/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ export function listViewPanel( state = false, action ) {
return state;
}

/**
* This reducer does nothing aside initializing a ref to the list view toggle.
* We will have a unique ref per "editor" instance.
*
* @param {Object} state
* @return {Object} Reference to the list view toggle button.
*/
export function listViewToggleRef( state = { current: null } ) {
return state;
}

export default combineReducers( {
blockInserterPanel,
listViewPanel,
Expand Down
15 changes: 3 additions & 12 deletions packages/editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/**
* External dependencies
*/
import createSelector from 'rememo';

/**
* WordPress dependencies
*/
import { store as blockEditorStore } from '@wordpress/block-editor';
import { createRegistrySelector } from '@wordpress/data';
import { createRef } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -52,9 +46,6 @@ export const getInsertionPoint = createRegistrySelector(
}
);

export const getListViewToggleRef = createSelector(
() => {
return createRef();
},
() => []
);
export function getListViewToggleRef( state ) {
return state.listViewToggleRef;
}
12 changes: 12 additions & 0 deletions packages/editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,17 @@ export function listViewPanel( state = false, action ) {
return state;
}

/**
* This reducer does nothing aside initializing a ref to the list view toggle.
* We will have a unique ref per "editor" instance.
*
* @param {Object} state
* @return {Object} Reference to the list view toggle button.
*/
export function listViewToggleRef( state = { current: null } ) {
return state;
}

export default combineReducers( {
postId,
postType,
Expand All @@ -365,4 +376,5 @@ export default combineReducers( {
removedPanels,
blockInserterPanel,
listViewPanel,
listViewToggleRef,
} );

0 comments on commit 18dd101

Please sign in to comment.