-
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
Fix uncaught TypeError in Columns block #14605
Fix uncaught TypeError in Columns block #14605
Conversation
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 change look good, I haven't tested it.
export default compose( | ||
/** | ||
* Selects the child column Blocks for this parent Column | ||
*/ | ||
withSelect( ( select, { clientId } ) => { | ||
const { getBlocksByClientId } = select( 'core/editor' ); | ||
const block = getBlocksByClientId( clientId )[ 0 ]; |
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.
Out of curiosity, I'm wondering if the following would work as well:
const { innerBlocks = DEFAULT_EMPTY_ARRAY } = getBlocksByClientId( clientId )[ 0 ];
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.
That won't work if the array returned by getBlocksByClientId
is empty. It'll result in something like:
"Can't destructure property 'innerBlocks' of 'undefined' or 'null'"
Description
The following error was discovered for the columns block:
To Reproduce:
The fix is just to ensure we're accessing
innerBlocks
property on a valid block object.How has this been tested?
Types of changes
This is a non-breaking bug fix.
Checklist: