-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Explore performance improvements #72535
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c3a7a1f
Don't subscribe in layout hasGlobalPadding if we know it doesn't
jeryj cca3582
Don't subscribe BorderPanel if it's not enabled for that block
jeryj 1a09914
Don't subscribe ColorEdit if it's not enabled for that block
jeryj c2b4d56
Don't subscribe dimensions panel to store if it's disabled
jeryj bb11e4b
Don't subscribe typography panel to store if it's disabled
jeryj 6b638d1
Don't subscribe PatternRenameModal to core store unless it's open
jeryj 77f14d7
Don't subscribe PatternDuplicateModal to core store unless it's open
jeryj b70e355
Don't mount init pattern modal unless on relevant post type
jeryj 6978a58
Combine blockEditorStore subscriptionsn for InbetweenInsertionPointPo…
jeryj 5c212ab
Combine block-tools subscriptions
jeryj e089485
Refactor useShowBlockTools into the single useSelect in BlockTools
jeryj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/block-editor/src/components/block-tools/should-show-block-tools.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { isUnmodifiedDefaultBlock } from '@wordpress/blocks'; | ||
|
|
||
| /** | ||
| * Determines which block tools should be showing based on the current editor state. | ||
| * This is a pure function that can be called from within a selector. | ||
| * | ||
| * @param {Object} options Calculation options. | ||
| * @param {Object} options.block The selected block object. | ||
| * @param {string} options.blockMode The block mode ('visual' or 'html'). | ||
| * @param {boolean} options.isBlockInterfaceHidden Whether the block interface is hidden. | ||
| * @param {string} options.clientId The selected block client ID. | ||
| * @param {boolean} options.isTyping Whether the user is currently typing. | ||
| * @param {boolean} options.hasFixedToolbar Whether the toolbar is fixed. | ||
| * | ||
| * @return {Object} Object of which block tools will be shown. | ||
| */ | ||
| export function shouldShowBlockTools( { | ||
| block, | ||
| blockMode, | ||
| isBlockInterfaceHidden, | ||
| clientId, | ||
| isTyping, | ||
| hasFixedToolbar, | ||
| } ) { | ||
| const hasSelectedBlock = !! clientId && !! block; | ||
| const isEmptyDefaultBlock = | ||
| hasSelectedBlock && | ||
| isUnmodifiedDefaultBlock( block, 'content' ) && | ||
| blockMode !== 'html'; | ||
| const showEmptyBlockSideInserter = | ||
| clientId && ! isTyping && isEmptyDefaultBlock; | ||
| const showBlockToolbarPopover = | ||
| ! isBlockInterfaceHidden && | ||
| ! hasFixedToolbar && | ||
| ! showEmptyBlockSideInserter && | ||
| hasSelectedBlock && | ||
| ! isEmptyDefaultBlock; | ||
|
|
||
| return { | ||
| showEmptyBlockSideInserter, | ||
| showBlockToolbarPopover, | ||
| }; | ||
| } |
77 changes: 35 additions & 42 deletions
77
packages/block-editor/src/components/block-tools/use-show-block-tools.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,46 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useSelect } from '@wordpress/data'; | ||
| import { isUnmodifiedDefaultBlock } from '@wordpress/blocks'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { store as blockEditorStore } from '../../store'; | ||
| import { unlock } from '../../lock-unlock'; | ||
|
|
||
| /** | ||
| * Source of truth for which block tools are showing in the block editor. | ||
| * Calculates which block tools should be showing based on the current editor state. | ||
| * This is a pure function that can be called from within a selector. | ||
| * | ||
| * @param {Object} options Calculation options. | ||
| * @param {Object} options.block The selected block object. | ||
| * @param {string} options.blockMode The block mode ('visual' or 'html'). | ||
| * @param {boolean} options.isBlockInterfaceHidden Whether the block interface is hidden. | ||
| * @param {string} options.clientId The selected block client ID. | ||
| * @param {boolean} options.isTyping Whether the user is currently typing. | ||
| * @param {boolean} options.hasFixedToolbar Whether the toolbar is fixed. | ||
| * | ||
| * @return {Object} Object of which block tools will be shown. | ||
| */ | ||
| export function useShowBlockTools() { | ||
| return useSelect( ( select ) => { | ||
| const { | ||
| getSelectedBlockClientId, | ||
| getFirstMultiSelectedBlockClientId, | ||
| getBlock, | ||
| getBlockMode, | ||
| getSettings, | ||
| isTyping, | ||
| isBlockInterfaceHidden, | ||
| } = unlock( select( blockEditorStore ) ); | ||
|
|
||
| const clientId = | ||
| getSelectedBlockClientId() || getFirstMultiSelectedBlockClientId(); | ||
|
|
||
| const block = getBlock( clientId ); | ||
| const hasSelectedBlock = !! clientId && !! block; | ||
| const isEmptyDefaultBlock = | ||
| hasSelectedBlock && | ||
| isUnmodifiedDefaultBlock( block, 'content' ) && | ||
| getBlockMode( clientId ) !== 'html'; | ||
| const _showEmptyBlockSideInserter = | ||
| clientId && ! isTyping() && isEmptyDefaultBlock; | ||
| const _showBlockToolbarPopover = | ||
| ! isBlockInterfaceHidden() && | ||
| ! getSettings().hasFixedToolbar && | ||
| ! _showEmptyBlockSideInserter && | ||
| hasSelectedBlock && | ||
| ! isEmptyDefaultBlock; | ||
| export function calculateShowBlockTools( { | ||
| block, | ||
| blockMode, | ||
| isBlockInterfaceHidden, | ||
| clientId, | ||
| isTyping, | ||
| hasFixedToolbar, | ||
| } ) { | ||
| const hasSelectedBlock = !! clientId && !! block; | ||
| const isEmptyDefaultBlock = | ||
| hasSelectedBlock && | ||
| isUnmodifiedDefaultBlock( block, 'content' ) && | ||
| blockMode !== 'html'; | ||
| const showEmptyBlockSideInserter = | ||
| clientId && ! isTyping && isEmptyDefaultBlock; | ||
| const showBlockToolbarPopover = | ||
| ! isBlockInterfaceHidden && | ||
| ! hasFixedToolbar && | ||
| ! showEmptyBlockSideInserter && | ||
| hasSelectedBlock && | ||
| ! isEmptyDefaultBlock; | ||
|
|
||
| return { | ||
| showEmptyBlockSideInserter: _showEmptyBlockSideInserter, | ||
| showBlockToolbarPopover: _showBlockToolbarPopover, | ||
| }; | ||
| }, [] ); | ||
| return { | ||
| showEmptyBlockSideInserter, | ||
| showBlockToolbarPopover, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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's the goal of this one? An early implementation of
shouldShowBlockTools?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.
Quick refactors as I go to see if they had an impact. I've heard from multiple folks that one of the performance hits of the codebase is how many selectors we have. So, if I come across a place while I'm debugging that I can quickly and easily refactor selectors into one, I'm doing it and moving on.
In this instance,
use-show-block-toolswas used in one place that was already using the same selectors, so I refactored so it could use the same subscription.This PR is a dumping ground for all the quick little things I come across to see if the drops in the bucket add up over time and improve code quality. If they do, then they can be spun out to separate PRs if needed.
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.
Ah - I didn't realize both versions were still around! I've made this sandbox PR a draft and moved this work over to #73012 to get officially reviewed.