-
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
Performance: only call useBlockEditingMode for selected blocks #57941
Conversation
*/ | ||
export default function HeadingLevelDropdown( { | ||
options = HEADING_LEVELS, | ||
value, | ||
onChange, | ||
} ) { | ||
const blockEditingMode = useBlockEditingMode(); |
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.
Alternatively we move the this to context and useBlockEditingMode
just grabs the context instead of subscribing to the store.
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.
This might be a more future-proof solution. Do you see any downsides to it?
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.
Might be good to get @noisysocks' opinion.
I think there are quite a few places that use useBlockEditingMode
in this way so if there's a way to reduce the performance impact in a more widespread way, it might indeed be a better option.
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.
Ok, I created #57950. That's a better solution.
Size Change: -23 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
@@ -32,14 +33,18 @@ const POPOVER_PROPS = { | |||
* Dropdown for selecting a heading level (1 through 6) or paragraph (0). | |||
* | |||
* @param {WPHeadingLevelDropdownProps} props Component props. | |||
* | |||
* @return {ComponentType} The toolbar. |
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.
This is giving me an error, not sure why, I didn't change the return at all.
/> | ||
</BlockControls> | ||
) } | ||
<BlockControls group="block"> |
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.
What?
See #57906. This is adding a store subscription for each paragraph and heading block.
Why?
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast