-
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
Block Editor: Don't memoize callbacks in 'BlockSettingsDropdown' #59397
Block Editor: Don't memoize callbacks in 'BlockSettingsDropdown' #59397
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@@ -233,7 +224,7 @@ export function BlockSettingsDropdown( { | |||
canRemove | |||
) { | |||
event.preventDefault(); | |||
updateSelectionAfterRemove( onRemove() ); | |||
updateSelectionAfterRemove(); |
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.
Size Change: -8 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
52d4b80
to
01f02a0
Compare
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.
Good find for all 3 of them 👍 🚀
}, | ||
[ __experimentalSelectBlock ] | ||
); | ||
async function updateSelectionAfterDuplicate( clientIdsPromise ) { |
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.
Only used inline; good to be un-memoized 👍
if ( ! blockToFocus ) { | ||
blockToFocus = getBlockOrder()[ 0 ]; | ||
} | ||
function updateSelectionAfterRemove() { |
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.
Only used inline; good to be un-memoized 👍
}, | ||
[ currentClientId, openedBlockSettingsMenu, setOpenedBlockSettingsMenu ] | ||
); | ||
function onToggle( localOpen ) { |
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.
While this is passed down, it's passed down to useControlledValue()
:
onChange: onToggle, |
which is then used for the initial value of useState()
, thus is utilized only on the first useState()
call anyway.
Good to be un-memoized as well 👍
[ __experimentalSelectBlock ] | ||
); | ||
async function updateSelectionAfterDuplicate( clientIdsPromise ) { | ||
if ( ! __experimentalSelectBlock ) { |
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.
Thanks for reducing the nesting level here 👍
…dPress#59397) * Block Editor: Don't memoize callbacks in 'BlockSettingsDropdown' * Don't pass argument to 'updateSelectionAfterRemove' Co-authored-by: Mamaduka <[email protected]> Co-authored-by: tyxla <[email protected]>
What?
PR removes unnecessary callback memoization in the
BlockSettingsDropdown
component.Why?
These callbacks aren't passed as effect dependencies or memoized component props. There's no need to ensure their stable reference.
Testing Instructions
Testing Instructions for Keyboard
Same.
Screenshots or screencast