-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
shimAttributeSource: don't run outside the registerBlockType filter #53015
Conversation
Size Change: -19 B (0%) Total Size: 1.44 MB
ℹ️ View Unchanged
|
@@ -124,26 +123,3 @@ addFilter( | |||
'core/editor/custom-sources-backwards-compatibility/shim-attribute-source', | |||
shimAttributeSource |
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.
Just to confirm, there's no way registerBlockType()
will be called before this filter has been added?
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.
registerBlockType
still can and will be called before adding this filter. But now there is a point, very late in the editor initialization, where the filters are re-applied. Basically re-registering the blocks once again. That's the __experimentalReapplyBlockTypeFilters
action. If some block got initially registered before all filters were added, the registration will be performed once again, with the new set of filters.
The core/blocks
store has two state slices for this: state.unprocessedBlockTypes
contains the raw block data with the filters unapplied, and state.blockTypes
contains the filtered block types. You can regenerated the blockTypes
from unprocessedBlockTypes
at any time, multiple times.
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.
Sounds good, thanks for confirming 👍
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.
Nice find, thanks for the cleanup 🚀
When adding back-compat support for
source: 'meta'
, theshimAttributeSource
function is called in ablocks.registerBlockType
filter, which is fine, but then it's also called statically, looping through all the blocks that were already registered. All this code was added in Feb 2020, in #20544, and it all made sense.Then, year and a half later, in Oct 2021, in #34299, @gziolo added new
__experimentalReapplyBlockTypeFilters
action, dispatched during editor initialization, which removes the need for the static loop. It re-runs theblocks.registerBlockType
filter, automatically catching all the early block registrations. This PR removes that static loop.Found this when working on async block loading in #51778 -- the static loop goes through all registered blocks, which doesn't work well with async loading.
How to test:
There is a e2e suite that tests for this specifically. There is a
meta-attribute-block
plugin that registers two blocks, one early and one late, and tests that they both get the `source: 'meta`` behavior right.