Bug/24286 create block error#24287
Conversation
packages/blocks/src/api/factory.js
Outdated
|
|
||
| if ( undefined === blockType ) { | ||
| warning( `Block type '${ name }' is not registered.` ); | ||
| return false; |
There was a problem hiding this comment.
Making this non-blocking changes the expectation from someone calling this function.
We do things like that in general in Gutenberg configs.map( config => createBlock( config.name, config.attributes, config.innerBlocks )
With the current implementation, this will hide bugs and just move them down the road. IMO, we should throw an exception here instead of calling warning.
There was a problem hiding this comment.
@youknowriad thanks for the review here! I have updated the PR to throw an exception.
| // Get the type definition associated with a registered block. | ||
| const blockType = getBlockType( name ); | ||
|
|
||
| if ( undefined === blockType ) { |
There was a problem hiding this comment.
Not important but yoda conditions are not a guideline in JavaScript because we enforce strict equality.
youknowriad
left a comment
There was a problem hiding this comment.
Thanks for your PR. The error message is way clearer this way.
closes #24286
Description
This PR implements the proposed solution indicated in #24286
How has this been tested?
Running `wp.blocks.createBlock('not/registered') in the console.
Screenshots
Types of changes
This introduces a warning() call and an early return if the blockType is not registered
Checklist: