-
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
Blocks: Apply the most recent filters to previously registered blocks #34299
Conversation
Size Change: +317 B (0%) Total Size: 1.07 MB
ℹ️ View Unchanged
|
dc1445a
to
ec3f8cc
Compare
eeaece0
to
096c7ea
Compare
Performance impact for 100 custom block types and 100 filters updating block types meassured with the following code: diff --git a/packages/blocks/src/store/controls.js b/packages/blocks/src/store/controls.js
index 9030abf01c..afc3baa19d 100644
--- a/packages/blocks/src/store/controls.js
+++ b/packages/blocks/src/store/controls.js
@@ -130,6 +130,7 @@ const controls = {
),
REAPPLY_BLOCK_TYPE_FILTERS: createRegistryControl(
( { dispatch, select } ) => () => {
+ const startTime = performance.now();
const unprocessedBlockTypes = select(
STORE_NAME
).__experimentalGetUnprocessedBlockTypes();
@@ -152,6 +153,11 @@ const controls = {
}
dispatch( STORE_NAME ).addBlockTypes( processedBlockTypes );
+
+ console.log(
+ 'Execution time (ms):',
+ performance.now() - startTime
+ );
}
),
}; Results:
Average time: 39 ms. |
addebe8
to
393278e
Compare
The usual dance to register blocks becomes quite messy and it is duplicated with customizations in 5 places for the web. We will have to improve it in a follow-up PR. Maybe, we could tackle it together with the migration to using the REST API endpoint for block types as explained in #22812. dispatch( blocksStore ).__experimentalReapplyBlockTypeFilters();
registerCoreBlocks();
if ( process.env.GUTENBERG_PHASE === 2 ) {
__experimentalRegisterExperimentalCoreBlocks();
} |
c954944
to
7f10bf3
Compare
7f10bf3
to
aaabad7
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.
I'm approving but I'm a bit worried about the impact of this PR :P
Fair enough. I'm worried as well. Let's see if it doesn't produce new issues when resolving some of those that existed for so long. |
Description
Fixes #9757.
Fixes #14578.
The problem
Same 3rd party blocks get registered with
registerBlockType
before other plugins register their filters that modify blocks during block registration.Implementation details
The proposed solution re-applies filters to the registered blocks just before the block editor starts the parsing step. At the moment it's applied only the edit post screen in the
initialize
function just before all core blocks get registered.The idea looks as follows:
addBlockTypes
action directly, a new__experimentalAddBlockType
action is called with the unprocessed block type. This action has two subactions:unprocessedBlockTypes
reducer.registerBlockType
method before.__experimentalReapplyBlockTypeFilters
that calls side-effects, that uses a new__experimentalGetUnprocessedBlockTypes
selector to get all registered unprocessed block types and applies all current filters (including those registered later) and updates the list of processed block types.There is no impact at all to the result of performance tests included as GitHub workflow because there are no 3rd party blocks registered.
TODO
I still plan to measure if registering a big number of 3rd party blocks and filters would have a negative impact on the performance of__experimentalReapplyBlockTypeFilters
action call and all the processing in the data control.See #34299 (comment).
Known Limitations
Ideally, we should be able to apply those filters at any time and all block definitions should magically update, but there are some architectural shortcomings that we would have to address first:
save
,attributes
orsupports
might impact the result of parsing the same block.How has this been tested?
I registered a test block and a test filter in the wrong order to validate if the filter is going to be reapplied.
Types of changes
Bug fix (non-breaking change which fixes an issue).
Checklist:
*.native.js
files for terms that need renaming or removal).