-
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
Use block context to detect presence of parent pattern for overrides #62861
Use block context to detect presence of parent pattern for overrides #62861
Conversation
Size Change: -6 B (0%) Total Size: 1.76 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.
I guess context makes sense.
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. |
@@ -292,6 +280,8 @@ function shimAttributeSource( settings, name ) { | |||
return { | |||
...settings, | |||
edit: withBlockBindingSupport( settings.edit ), | |||
// TODO - move this to be located with pattern overrides code. | |||
usesContext: [ 'patternOverridesContent', ...settings?.usesContext ], |
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.
Should we move this to the usesContext
property when registering the pattern overrides source?
'uses_context' => array( 'pattern/overrides' ), |
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.
Will this also register usesContext
for client side code?
Considering both pattern/overrides
and patternOverridesContent
are both sharing the same attribute via context, I guess they should be named the same thing. I'm not enamoured with using pattern/overrides
naming in js code where the variable is often accessed via dot notation or destructuring.
I think changing it would require a backport.
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.
Will this also register usesContext for client side code?
If not, I think it could still be moved to this file if we change it over to the registerBlockType
hook similar to the one in the use-binding-attributes.js
file:
https://github.com/WordPress/gutenberg/blob/trunk/packages/editor/src/hooks/pattern-overrides.js#L110
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.
Will this also register usesContext for client side code?
Yes, it should work client-side. We might make some changes to how it is handled, but it should work.
I'm not familiar with how that context is used, but it'd be great to use just one property if possible.
I think changing it would require a backport.
Yes, I think it would need one. But it should be just one line.
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 decided to change it to pattern/overrides
on the client as well, so that it's consistent and we won't need a backport.
I think I've addressed all the feedback.
I agree that using the context makes sense. Thanks for working on that! 🙂 I can see we have similar logic in the image edit file: link. Should we use context there as well? |
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.
Using block context makes sense to me as well. After a round of testing, everything seems to be working as expected, and automated tests are passing.
9ee6ad3
into
fix/aspect-ratio-not-working-in-image-with-overrides
…es (#62828) * Remove only supported attributes * Try alternative approach * Update comment * Return early while editing the original pattern * Move conditional inside conditional * Add missing check * Go back to running always bindings * Use block context to detect presence of parent pattern for overrides (#62861) * Use block context to detect presence of parent pattern * Regenerate fixtures * Update image block to use context for checking a parent pattern block exists * Rename context to `pattern/overrides` to be consistent with php code * Move pattern overrides context shim to pattern overrides hooks * Remove shim Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org> * Reduce diff * Change array order --------- Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org> Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
…es (#62828) * Remove only supported attributes * Try alternative approach * Update comment * Return early while editing the original pattern * Move conditional inside conditional * Add missing check * Go back to running always bindings * Use block context to detect presence of parent pattern for overrides (#62861) * Use block context to detect presence of parent pattern * Regenerate fixtures * Update image block to use context for checking a parent pattern block exists * Rename context to `pattern/overrides` to be consistent with php code * Move pattern overrides context shim to pattern overrides hooks * Remove shim Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org> * Reduce diff * Change array order --------- Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org> Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
What?
Based on the branch from #62828, tries using block context to detect a parent pattern as an alternative to using selectors and traversing up the block tree.
Why?
Improved performance.
This also more closely matches the server implementation.
How?
providesContext
to the pattern block's block.json, providing thecontent
attributecontent
attribute so that it's always truthy (the code can consistently check for a parent pattern using the attribute.usesContext
for the content attribute to all supported block binding blockscontext
check.Testing Instructions
Follow the testing instructions in #62828