-
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
Bug/24286 create block error #24287
Bug/24286 create block error #24287
Changes from 7 commits
96b832f
e5a20f4
b5d9c57
f2caf37
4843ff7
937de91
b1dad82
594b9c4
d125251
1e68ce0
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ import { | |
* WordPress dependencies | ||
*/ | ||
import { createHooks, applyFilters } from '@wordpress/hooks'; | ||
import warning from '@wordpress/warning'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -40,12 +41,17 @@ import { normalizeBlockType } from './utils'; | |
* @param {Object} attributes Block attributes. | ||
* @param {?Array} innerBlocks Nested blocks. | ||
* | ||
* @return {Object} Block object. | ||
* @return {(Object|boolean)} Block object or false if the block name is not a registered block. | ||
*/ | ||
export function createBlock( name, attributes = {}, innerBlocks = [] ) { | ||
// Get the type definition associated with a registered block. | ||
const blockType = getBlockType( name ); | ||
|
||
if ( undefined === blockType ) { | ||
warning( `Block type '${ name }' is not registered.` ); | ||
return false; | ||
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. Making this non-blocking changes the expectation from someone calling this function. We do things like that in general in Gutenberg 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 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. @youknowriad thanks for the review here! I have updated the PR to throw an exception. |
||
} | ||
|
||
// Ensure attributes contains only values defined by block type, and merge | ||
// default values for missing attributes. | ||
const sanitizedAttributes = reduce( | ||
|
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.
Not important but yoda conditions are not a guideline in JavaScript because we enforce strict equality.