-
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: Add a warning when registering variation without a name #61037
Conversation
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. |
Size Change: +25 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
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.
if ( typeof variation.name !== 'string' ) { | ||
console.warn( 'Variation names must be unique strings.' ); | ||
} |
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.
This could use a simple unit test. We're already testing all the console.error
instances in registerBlockType()
for example.
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.
Added in 238d4d0
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.
Thanks! Feel free to 🚢 when green.
@@ -723,6 +723,10 @@ export const getBlockVariations = ( blockName, scope ) => { | |||
* ``` | |||
*/ | |||
export const registerBlockVariation = ( blockName, variation ) => { | |||
if ( typeof variation.name !== 'string' ) { | |||
console.warn( 'Variation names must be unique strings.' ); |
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.
We currently use console.error
for similar errors during block (un)registration with registerBlockType
and unregisterBlockType
. Is there a good reason to prefer a warning to an error? Perhaps because we want the application to continue running as usual (which is why we don't return early too)?
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 decided to use the warning because, unlike registerBlockType
, this doesn't prevent registration.
It should be more of a hint to folks that they're incorrectly registering block variation instead of a breaking change.
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.
Thanks for confirming 👍
It looks like official docs has similar notice. I'll chat with @ndiego about updating both sources. |
Just want to confirm that variations without a unique name will still work, right? I have seen tons of variation code without unique names out in the wild 😅 |
Yes, they will work as before. There are no breaking changes here. We were just wondering if we still want to highlight that fact, or maybe we could change the wording and encourage people to use the |
@ndiego Do you have specific examples that I could try out? I'm really curious because IMO they shouldn't work 😄 |
238d4d0
to
348e112
Compare
Flaky tests detected in 348e112. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8817419828
|
What?
This is a follow-up to #60832.
PR adds a warning to block the variation registration method when the variation name is missing. The registrar's behavior remains the same.
Why?
The block variations must have a unique name to work correctly in the block editor.
How
The method is the soft version of the
registerBlockType
function validation.Testing Instructions
Test snippet
Testing Instructions for Keyboard
Same.
Screenshots or screencast