-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Unmemoize Block component selectors #58355
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
Changes from 3 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 |
|---|---|---|
|
|
@@ -44,6 +44,10 @@ export function getLastInsertedBlocksClientIds( state ) { | |
| return state?.lastBlockInserted?.clientIds; | ||
| } | ||
|
|
||
| export function getBlockWithoutAttributes( state, clientId ) { | ||
| return state.blocks.byClientId.get( clientId ); | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if all of the descendants of a block with the given client ID | ||
| * have an editing mode of 'disabled', or false otherwise. | ||
|
|
@@ -53,25 +57,17 @@ export function getLastInsertedBlocksClientIds( state ) { | |
| * | ||
| * @return {boolean} Whether the block descendants are disabled. | ||
| */ | ||
| export const isBlockSubtreeDisabled = createSelector( | ||
| ( state, clientId ) => { | ||
| const isChildSubtreeDisabled = ( childClientId ) => { | ||
| return ( | ||
| getBlockEditingMode( state, childClientId ) === 'disabled' && | ||
| getBlockOrder( state, childClientId ).every( | ||
| isChildSubtreeDisabled | ||
| ) | ||
| ); | ||
| }; | ||
| return getBlockOrder( state, clientId ).every( isChildSubtreeDisabled ); | ||
| }, | ||
| ( state ) => [ | ||
| state.blocks.parents, | ||
| state.blocks.order, | ||
| state.blockEditingModes, | ||
| state.blockListSettings, | ||
| ] | ||
| ); | ||
| export const isBlockSubtreeDisabled = ( state, clientId ) => { | ||
| const isChildSubtreeDisabled = ( childClientId ) => { | ||
| return ( | ||
| getBlockEditingMode( state, childClientId ) === 'disabled' && | ||
| getBlockOrder( state, childClientId ).every( | ||
| isChildSubtreeDisabled | ||
| ) | ||
| ); | ||
| }; | ||
| return getBlockOrder( state, clientId ).every( isChildSubtreeDisabled ); | ||
| }; | ||
|
Member
Author
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. After #58349, this is no longer called, so the performance improvement of this PR will be lessened.
Member
Author
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. Probably still worth to remove the memoization I think... Also the dependencies of this selector weren't fully correct.
Member
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. Also, this selector should also check the editing mode of the top-level If I look at the only call in |
||
|
|
||
| /** | ||
| * Returns a tree of block objects with only clientID and innerBlocks set. | ||
|
|
||
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.
The reason this is better than selector cache is because it's stored by component instance, not globally.