Skip to content

Conversation

@girishpanchal30
Copy link
Contributor

Closes #2696

Summary

Check if the theme supports block-template-part or block-template to enqueue the assets.

Checklist before the final review

  • Included E2E or unit tests for the changes in this PR.
  • Visual elements are not affected by independent changes.
  • It is at least compatible with the minimum WordPress version.
  • It loads additional script in frontend only if it is required.
  • Does not impact the Core Web Vitals.
  • In case of deprecation, old blocks are safely migrated.
  • It is usable in Widgets and FSE.
  • Copy/Paste is working if the attributes are modified.
  • PR is following the best practices

@girishpanchal30 girishpanchal30 added the pr-checklist-skip Allow this Pull Request to skip checklist. label Dec 26, 2025
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label Dec 26, 2025
@girishpanchal30 girishpanchal30 linked an issue Dec 26, 2025 that may be closed by this pull request
@pirate-bot
Copy link
Contributor

Bundle Size Diff

Package Old Size New Size Diff
Animations 271.38 KB 271.38 KB 0 B (0.00%)
Blocks 1.54 MB 1.54 MB 0 B (0.00%)
CSS 100.76 KB 100.76 KB 0 B (0.00%)
Dashboard 198.36 KB 198.36 KB 0 B (0.00%)
Onboarding 160.8 KB 160.8 KB 0 B (0.00%)
Export Import 97.73 KB 97.73 KB 0 B (0.00%)
Pro 407.08 KB 407.08 KB 0 B (0.00%)

@pirate-bot
Copy link
Contributor

pirate-bot commented Dec 26, 2025

Plugin build for 0bd41ce is ready 🛎️!

@pirate-bot
Copy link
Contributor

pirate-bot commented Dec 30, 2025

E2E Tests

Playwright Test Status:

Performance Results serverResponse: {"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}

@rodica-andronache
Copy link

@girishpanchal30 can you please help me test this?
I've tried creating a child theme for Neve, with support for block templates parts, and tested with this PR, but I'm not seeing any change, and I'm not sure if I'm testing properly
neve-child-master.zip

image image

@girishpanchal30
Copy link
Contributor Author

@rodica-andronache I have fixed it with the latest commit. Please check it and let me know if any changes are needed.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-parts alongside block-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.

Comment on lines +610 to +616
// 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;
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 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;
}

Copilot uses AI. Check for mistakes.
Comment on lines +433 to 441
// 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;
}
}
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 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 = '';

Copilot uses AI. Check for mistakes.
$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' );
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
$templates_parts = get_block_templates( array( 'slug__in' => $slugs ), 'wp_template_part' );
$templates_parts = get_block_templates( array( 'slugs__in' => $slugs ), 'wp_template_part' );

Copilot uses AI. Check for mistakes.
$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' );
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
$templates_parts = get_block_templates( array( 'slug__in' => $slugs ), 'wp_template_part' );
$templates_parts = get_block_templates( array( 'slugs__in' => $slugs ), 'wp_template_part' );

Copilot uses AI. Check for mistakes.
@rodica-andronache
Copy link

it's working well now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assets are not enqueued for block template parts

5 participants