Enqueued assets for block template#2729
Conversation
Bundle Size Diff
|
|
Plugin build for 0bd41ce is ready 🛎️!
|
E2E TestsPlaywright Test Status: Performance ResultsserverResponse: {"q25":411.8,"q50":414.55,"q75":421.2,"cnt":10}, firstPaint: {"q25":435.2,"q50":463.65,"q75":497.5,"cnt":10}, domContentLoaded: {"q25":1462.1,"q50":1473.85,"q75":1513.3,"cnt":10}, loaded: {"q25":1462.4,"q50":1474.15,"q75":1513.8,"cnt":10}, firstContentfulPaint: {"q25":3129.5,"q50":3157.4,"q75":3196.5,"cnt":10}, firstBlock: {"q25":6461.7,"q50":6513.3,"q75":6579.9,"cnt":10}, type: {"q25":12.32,"q50":12.7,"q75":13.04,"cnt":10}, typeWithoutInspector: {"q25":11.25,"q50":11.47,"q75":11.65,"cnt":10}, typeWithTopToolbar: {"q25":15.98,"q50":16.97,"q75":17.16,"cnt":10}, typeContainer: {"q25":6.87,"q50":7.26,"q75":8.69,"cnt":10}, focus: {"q25":51.29,"q50":52.29,"q75":54.44,"cnt":10}, inserterOpen: {"q25":16.15,"q50":17.1,"q75":18.74,"cnt":10}, inserterSearch: {"q25":5.56,"q50":5.67,"q75":6.12,"cnt":10}, inserterHover: {"q25":2.36,"q50":2.41,"q75":2.5,"cnt":20}, loadPatterns: {"q25":1037.75,"q50":1062.18,"q75":1084.11,"cnt":10}, listViewOpen: {"q25":88.72,"q50":90.14,"q75":93.97,"cnt":10} |
|
@girishpanchal30 can you please help me test this?
|
|
@rodica-andronache I have fixed it with the latest commit. Please check it and let me know if any changes are needed. |
There was a problem hiding this comment.
Pull request overview
This pull request updates the asset enqueuing logic to support themes that use block-template-parts in addition to those that use full block-templates. This allows the plugin to work correctly with classic themes that have adopted block-based template parts.
Changes:
- Modified theme support checks to include
block-template-partsalongsideblock-templates - Added fallback logic to load all template parts when full template content is unavailable
- Updated test selectors to match WordPress block editor's namespaced class structure
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/blocks/test/performance/specs/post-editor.spec.js | Updates CSS selectors for block inserter items to include block namespace |
| inc/css/class-block-frontend.php | Modifies FSE CSS enqueuing to support block-template-parts and adds fallback logic |
| inc/class-registration.php | Updates dependency enqueuing conditions and logic to handle block-template-parts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Fallback for classic themes with block-template-parts only. | ||
| // Get all template parts since we can't determine which ones are used. | ||
| $templates_parts = get_block_templates( array(), 'wp_template_part' ); | ||
|
|
||
| foreach ( $templates_parts as $templates_part ) { | ||
| if ( ! empty( $templates_part->content ) ) { | ||
| $content .= $templates_part->content; |
There was a problem hiding this comment.
Loading all template parts when $_wp_current_template_content is empty could have performance implications, especially on sites with many template parts. Consider documenting this as a known limitation or exploring alternative approaches to determine which template parts are actually being used.
| // Fallback for classic themes with block-template-parts only. | |
| // Get all template parts since we can't determine which ones are used. | |
| $templates_parts = get_block_templates( array(), 'wp_template_part' ); | |
| foreach ( $templates_parts as $templates_part ) { | |
| if ( ! empty( $templates_part->content ) ) { | |
| $content .= $templates_part->content; | |
| /** | |
| * Fallback for classic themes with block-template-parts only. | |
| * | |
| * Note: This fallback loads all registered template parts when | |
| * $_wp_current_template_content is empty, because there is no reliable | |
| * way to detect which ones are actually referenced. On sites with many | |
| * template parts this may have performance implications, since all of | |
| * them are queried and parsed in order to extract CSS. | |
| * | |
| * Developers can disable this behavior by filtering | |
| * 'themeisle_gutenbergblocks_load_all_template_parts' and returning | |
| * false when they do not need CSS to be generated from template parts | |
| * in this fallback scenario. | |
| */ | |
| $load_all_template_parts = apply_filters( 'themeisle_gutenbergblocks_load_all_template_parts', true ); | |
| if ( $load_all_template_parts ) { | |
| // Get all template parts since we can't determine which ones are used. | |
| $templates_parts = get_block_templates( array(), 'wp_template_part' ); | |
| foreach ( $templates_parts as $templates_part ) { | |
| if ( ! empty( $templates_part->content ) ) { | |
| $content .= $templates_part->content; | |
| } |
| // Fallback for classic themes with block-template-parts only. | ||
| // Get all template parts since we can't determine which ones are used. | ||
| $templates_parts = get_block_templates( array(), 'wp_template_part' ); | ||
|
|
||
| foreach ( $templates_parts as $templates_part ) { | ||
| if ( ! empty( $templates_part->content ) ) { | ||
| $content .= $templates_part->content; | ||
| } | ||
| } |
There was a problem hiding this comment.
Loading all template parts when $_wp_current_template_content is empty could have performance implications, especially on sites with many template parts. Consider documenting this as a known limitation or exploring alternative approaches to determine which template parts are actually being used.
| // Fallback for classic themes with block-template-parts only. | |
| // Get all template parts since we can't determine which ones are used. | |
| $templates_parts = get_block_templates( array(), 'wp_template_part' ); | |
| foreach ( $templates_parts as $templates_part ) { | |
| if ( ! empty( $templates_part->content ) ) { | |
| $content .= $templates_part->content; | |
| } | |
| } | |
| // Fallback when the current template content is not available. | |
| // We cannot reliably determine which template parts are used here. | |
| // To avoid loading and parsing all template parts (which can have | |
| // significant performance implications on large sites), we skip | |
| // template-part-based dependency detection in this scenario. | |
| $content = ''; |
| $content .= $templates_part->content; | ||
|
|
||
| // Get the specific template parts referenced in the template. | ||
| $templates_parts = get_block_templates( array( 'slug__in' => $slugs ), 'wp_template_part' ); |
There was a problem hiding this comment.
The parameter name should be 'slugs__in' (with an 's'), not 'slug__in'. This is inconsistent with the existing usage in the codebase (see inc/class-blocks-css.php line 134) and will cause the slug filtering to not work correctly.
| $templates_parts = get_block_templates( array( 'slug__in' => $slugs ), 'wp_template_part' ); | |
| $templates_parts = get_block_templates( array( 'slugs__in' => $slugs ), 'wp_template_part' ); |
| $content .= $templates_part->content; | ||
|
|
||
| // Get the specific template parts referenced in the template. | ||
| $templates_parts = get_block_templates( array( 'slug__in' => $slugs ), 'wp_template_part' ); |
There was a problem hiding this comment.
The parameter name should be 'slugs__in' (with an 's'), not 'slug__in'. This is inconsistent with the existing usage in the codebase (see inc/class-blocks-css.php line 134) and will cause the slug filtering to not work correctly.
| $templates_parts = get_block_templates( array( 'slug__in' => $slugs ), 'wp_template_part' ); | |
| $templates_parts = get_block_templates( array( 'slugs__in' => $slugs ), 'wp_template_part' ); |
|
it's working well now |


Closes #2696
Summary
Check if the theme supports
block-template-partorblock-templateto enqueue the assets.Checklist before the final review