-
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
Do not look for block variants, if not supporting block-templates #45362
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
I don't know the details of how it works, but I am concerned that it may affect the classic theme that supports template parts. In the Classic theme, opt-in the Template Parts Editor as follows: function add_block_template_part_support() {
add_theme_support( 'block-template-parts' );
}
add_action( 'after_setup_theme', 'add_block_template_part_support' ); Then, when we try to load other template parts within the template parts editor, the behavior changes. On trunkOn this branch |
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.
This looks good to me based on manual testing.
Note:
On my Gutenberg development box, I needed to modify the equivelant path in WordPress, /wp-includes/blocks/template-part.php
, to confirm this change.
For whatever reason, the plugin wasn't using its version of the PHP files.
Having dug in to this following @t-hamano 's comment above, I think it needs to return early with the following: if (
! current_theme_supports( 'block-templates' )
&& ! current_theme_supports( 'block-template-parts' )
) {
return [];
}
|
This is a performance issue? The ticket/PR is a bit light on details. This idea behind this PR seems like an ok patch for a short term improvement in 6.1.1, but doesn't really get to the core of the issue. Other code can still call The two questions I have:
It might be good to look at a different fix for 6.2. |
@peterwilsoncc, I don't think that's true. Those are two separate "flags" for classic themes. |
@Mamaduka This is what I see in TT3, which includes template parts but doesn't indicate
Maybe there is some nuance that I am missing re the purpose the theme support flags serve. @talldan Yeah, a perf issue to avoid unneeded DB queries. Thanks for tagging appropriately. I think you're right, there is room to improve further in 6.2 by basically nooping any of the database queries template blocks make. |
@peterwilsoncc, the Internally the flag controls what pieces of the UI are hidden/inaccessible. Here's a dev note for more details: https://make.wordpress.org/core/2022/10/04/block-based-template-parts-in-traditional-themes/. |
Can you pull and tests again @t-hamano |
I have checked the behavior again and it is working as expected. I also checked again the support variations in the classic theme, and I believe they are as follows: Support
|
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
I guess the question is, do we even need to register this block on themes that do not support them anyway. Seems like it would never be used. |
I would love some context here from @talldan. |
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 changes here look good to me. Thank you, @spacedmonkey!
I agree with @talldan that we should explore a more general solution for WP 6.2.
Even for the block themes, variations are only needed by the editors. There's no use in querying them when a user visits a page.
One option we can explore for the next major release is the lazy initialization of block variables.
Created a ticket #45601. |
Could the concerns of #45362 (comment) above also be addressed, please? I think no database queries for theme support, and especially not anything via WP Query, should be performed before a template can be determined ( |
…5362) * Do not look for block varients, if not supporting block-templates * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
…5362) * Do not look for block varients, if not supporting block-templates * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
What?
Do not look for block variants if theme does not support them. Saving a database query.
Original ticket here.
Why?
How?
Testing Instructions
Screenshots or screencast