-
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: Optimize BlockListAppender #56116
Conversation
if ( renderAppender === false ) { | ||
return null; | ||
} |
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 we're mostly doing is moving this condition a level above and moving the rest to a subcomponent. That way if the appender is false
, we'll not have to create extra subscriptions because the subcomponent will never be rendered.
Size Change: +22 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
Nice. I've also noticed this but was taking a different approach - returning early in But I think your approach is cleaner! I'll properly test the PR shortly. My version
diff --git packages/block-editor/src/components/block-list-appender/index.js packages/block-editor/src/components/block-list-appender/index.js
index 7b37b93d8b..5aab6200b5 100644
--- packages/block-editor/src/components/block-list-appender/index.js
+++ packages/block-editor/src/components/block-list-appender/index.js
@@ -42,6 +42,10 @@ function DefaultAppender( { rootClientId } ) {
function useAppender( rootClientId, CustomAppender ) {
const isVisible = useSelect(
( select ) => {
+ if ( CustomAppender === false ) {
+ return false;
+ }
+
const {
getTemplateLock,
getSelectedBlockClientId,
@@ -49,10 +53,6 @@ function useAppender( rootClientId, CustomAppender ) {
getBlockEditingMode,
} = select( blockEditorStore );
- if ( CustomAppender === false ) {
- return false;
- }
-
if ( ! CustomAppender ) {
const selectedBlockClientId = getSelectedBlockClientId();
const isParentSelected =
@@ -96,6 +96,10 @@ function BlockListAppender( {
const appender = useAppender( rootClientId, renderAppender );
const isDragOver = useSelect(
( select ) => {
+ if ( ! appender ) {
+ return false;
+ }
+
const {
getBlockInsertionPoint,
isBlockInsertionPointVisible,
@@ -111,7 +115,7 @@ function BlockListAppender( {
getBlockCount( rootClientId ) === 0
);
},
- [ rootClientId ]
+ [ rootClientId, appender ]
);
if ( ! appender ) { |
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.
Thank you, @tyxla!
I couldn't spot any regressions. Tested with various container blocks.
What?
Similar to #56101.
This PR updates the
BlockListAppender
component to render the appender only if the appender component is not specifically set to befalse
. In the case offalse
, we never render it anyway, so with this change we'll not add unnecessary extra store subscriptions. The primary difference is that we're now doing that check outside of theuseSelect
call.Why?
This is an effort to minimize unnecessary store subscriptions created per block. See #54819 (comment).
Tested using @jsnajdr's debug code (c029303), the store subscriptions are reduced by almost 1k (~2%) on large text post with 1000 blocks.
Testing Instructions
Testing Instructions for Keyboard
No specific instructions.
Screenshots or screencast
None