-
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
Block categories - ensure that categories are unique by slug. #62954
Conversation
Block categories can be registered through backend by hooking into the "block_categories_all"-filter or through frontend by calling wp.blocks.setCategories(). Both require an array of WPBlockCategory elements. This change aims for making the categories: WPBlockCategory[] with unique entries by slug to avoid rendering in Block Inserter all Blocks duplicated. See also: WordPress#50061
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @Chrico! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
Thanks for the contribution @Chrico! Would you be able to add a unit test as well that tests the uniqueness? This is where the tests are currently located: gutenberg/packages/blocks/src/store/test/reducer.js Lines 405 to 520 in 1c3e7be
|
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.
Code looks good and this is testing well, thank you for the contribution
Thanks...but I also missed to write the changelog...This is a breaking fix change (in theory), right? 👀 |
If you want to make a PR for that, I'd be happy to merge it too, you can add an entry to the 'Unreleased' section in the blocks package. I'd personally consider it a bug fix, I'm not sure I'd consider it a breaking change. The package's interface is still the same, it's only the internal behavior that's very slightly different. |
Fixes #50061
What?
Block categories can be registered through backend by hooking into the "block_categories_all"-filter or through frontend by calling
wp.blocks.setCategories()
. Both require an array ofWPBlockCategory
elements. This change aims for making thecategories: WPBlockCategory[]
with unique entries by slug to avoid rendering in Block Inserter all Blocks duplicated.See also: #50061
Testing Instructions
Go to "New Post" (or "Edit Post"), open DevTools and insert following:
Open afterwards the "Block Inserter". You will see now "Theme", "My Title" and "Meeeh" with exactly 3 times the same Blocks. With this fix we ensure, that only 1 Group is shown with the Blocks.
Open Questions
Right now, the last entry "wins". Should we show a message (
console.info()
?) when an entry is overwritten by a matching slug?