-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.' ); | ||
} | ||
Comment on lines
+726
to
+728
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Feel free to 🚢 when green. |
||
|
||
dispatch( blocksStore ).addBlockVariations( blockName, variation ); | ||
}; | ||
|
||
|
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 withregisterBlockType
andunregisterBlockType
. 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 👍