-
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
InnerBlocks: Make sure blockType is set before trying to use it #63351
InnerBlocks: Make sure blockType is set before trying to use it #63351
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. |
if ( Object.keys( blockType.providesContext ).length === 0 ) { | ||
if ( | ||
! blockType?.providesContext || | ||
Object.keys( blockType.providesContext ).length === 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.
I'm still not fully understanding how it's possible to have inner blocks without a block type. Could you give an 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.
Honestly, I am not sure how this is happening either! But, it happens in the scenario mentioned in the description with WooCommerce's use of blocks in the new product editor. Ultimately, the root problem may lie somewhere in WooCommerce's handling of blocks, but this change seems like a reasonable defensive change in GB.
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.
Yes, I'm still curious. This is a legitimate error tbh, but sure, let's gracefully fail.
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.
Agreed. We will still be attempting to address the root cause of this! I'm very curious too.
Co-authored-by: mattsherman <mattormeeple@git.wordpress.org>
What?
This PR adds a check that
blockType
is set before attempting to use it inInnerBlocks
.Why?
This PR addresses an error that is thrown in the context of the WooCommerce new product editor when generating product variations. See woocommerce/woocommerce#49216 for a try branch that triggers the error.
Without this fix, whenever variations are generated, the following error is logged in the browser dev console (note, we worked around the error in the UI in woocommerce/woocommerce#49248, so it does not crash WooCommerce).
How?
This PR adds a check that
blockType
is set before attempting to use it inInnerBlocks
.Testing Instructions
With the Gutenberg plugin built from this PR and a WooCommerce env running the branch from woocommerce/woocommerce#49216 with the new product editor enabled (WooCommerce > Settings > Advanced > Features > Experimental features)...
Variations
tab, clickAdd Options
and add some variation options.Variations
TypeError: undefined is not an object (evaluating 'w.providesContext')
error was logged in the browser dev console.Testing Instructions for Keyboard
n/a
Screenshots or screencast
n/a