-
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
Inner Blocks: Fix provides context condition #46729
Conversation
if ( | ||
Object.keys( blockType?.providesContext ?? {} ).length === 0 | ||
) { | ||
return { name: block.name }; |
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.
The name
is used later to get the block layout. Since early return wasn't working, not returning it was never an issue.
Size Change: +19 B (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
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.
Looks good and makes sense to me 👍
I believe it could be worth a unit test, but that's up to you.
Thanks 🚀
I'm definitely planning to do that as a part of my next PR. I just need to figure out the right amount of "unit" to test 😅 |
The mobile version of the if ( blockType && blockType.providesContext ) { /* ... */ } And it's always truthy as well? If true, this component should get the same fix. |
What?
PR fixes early return condition check when block type doesn't provide context.
Why?
The default
providesContext
value is an empty object. Since its truthy value, the early return condition was never met.The
getBlockContext
will return a new object on every attribute change and cause extra re-render. This is another issue I'm trying to solve.How?
Use
Object.keys
to check if the block type defines the context to provide.Testing Instructions
Testing Instructions for Keyboard
Doesn't affect UI.