-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inserter: Return the same items when the state and parameters don't change #62263
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,8 @@ const EMPTY_ARRAY = []; | |
*/ | ||
const EMPTY_SET = new Set(); | ||
|
||
const EMPTY_OBJECT = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've omitted the comment here. The other ones are a bit outdated and we should probably revise them together. |
||
|
||
/** | ||
* Returns a block's name given its client ID, or null if no block exists with | ||
* the client ID. | ||
|
@@ -1996,7 +1998,7 @@ const buildBlockTypeItem = | |
*/ | ||
export const getInserterItems = createRegistrySelector( ( select ) => | ||
createSelector( | ||
( state, rootClientId = null, options = {} ) => { | ||
( state, rootClientId = null, options = EMPTY_OBJECT ) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I guess this doesn't matter because |
||
const buildReusableBlockInserterItem = ( reusableBlock ) => { | ||
const icon = ! reusableBlock.wp_pattern_sync_status | ||
? { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we account for this in
getInserterItems
? Also the default there is an empty object on every call, so we should change that too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be ideal, but we need to figure out how. Functions have no control over the arguments they receive.
Yes. We should either pass
undefined
or anEMTPY_OBJECT
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is a good fix for now. I wonder if we should just create another private
getInserterItems
selector and avoid the options altogether. Actually this would also allow us to remove all the reusable blocks logic. We're adding these blocks, just to filter them back out in the UI 😄