Skip to content
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

Fix registry update for different post types #200

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

kuuak
Copy link
Contributor

@kuuak kuuak commented Oct 13, 2023

If we do not have the same registered blocks per post types the registry will be updated without all the available blocks.

Here a basic example:

If I have 3 available blocks core/heading, core/paragraph and custom/section.
Let's assume I do not need the custom/section in the Post post-type, therefore I have some custom code to checks if the current post type in the editor is post, and if so I unregister the custom/section block.

This means that when the registerBlockRegistryUpdate plugin run, it retrieves the available blocks, in this situation two blocks, and make the block registry to be updated with these 2 blocks.

But now I if I open the editor to edit a page, my custom code does not unregister the section block, and the registerBlockRegistryUpdate updates the registry with 3 blocks.

This is really a basic example where I have 1 missing block in the registry if the last content update was a Post.

But in my real usage I have more than 100 available blocks that can be available for one or many post types. I end up with sometimes 22 blocks in the registry, or 50 or more than a 100 when I manually hit the "Update block registry" button in the setting page.

My quick fix is then to I disabled the two editor plugins which updated the block registry with the current post type registered blocks.

kuuak added 4 commits October 13, 2023 11:36
Avoid the block registry to be updated when opening the block editor.
If we do not have the same registered blocks per post types
the registry will be updated without all the available blocks.
⚠️ Disabling this, means that you have to manually hit the
"Update block registry" button in the settings page.
@mboynes
Copy link

mboynes commented Dec 12, 2024

@kuuak I'm not sure that this PR will really address the issue, because updating the registry through the settings button might still leave some block registrations out depending on the contexts where they're registered (like other post types). what I did as a workaround for this issue is merge the block registry into the database on update, vs replace the old value. This was good enough for my use case, but I'll confess that it's not perfect; if two post types register a block differently (e.g. a different default attribute value), they will still overwrite each other. A more robust solution would be to store multiple registries, one per post type, and load the appropriate registry based on the post returned in gql.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants