Skip to content
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

Fix flash when clicking template name in the editor when a plugin registered template matches a default WP theme template #66359

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.7/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function _gutenberg_add_block_templates_from_registry( $query_result, $query, $t
}

if ( ! isset( $query['wp_id'] ) ) {
$template_files = _gutenberg_get_block_templates_files( $template_type, $query );
$template_files = _gutenberg_get_block_templates_files( $template_type );
Copy link
Contributor

@anton-vlasenko anton-vlasenko Oct 28, 2024

Choose a reason for hiding this comment

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

If the issue is related to filtering templates by post_type, what if we try removing only the problematic post_type key instead of the entire $query array?
This might resolve the issue while maintaining relatively good performance, as it would remove the need to fetch all block template files.

What do you think, @Aljullu?

Suggested change
$template_files = _gutenberg_get_block_templates_files( $template_type );
// Inline comment explaining why the $query is not used.
$template_files_query = $query;
unset( $template_files_query['post_type'] );
$template_files = _gutenberg_get_block_templates_files( $template_type, $template_files_query );

Additionally, adding an inline comment to explain why the query array isn’t passed to the _gutenberg_get_block_templates_files() function would make it easier to understand the code and reduce the risk of it being overwritten later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, I applied the changes in 1641d59.

Copy link
Contributor

@anton-vlasenko anton-vlasenko Oct 29, 2024

Choose a reason for hiding this comment

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

It would be nice to add a unit test to prevent this bug from reoccurring, but it’s not a blocker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I added the tests directly to the backport PR in WordPress/wordpress-develop#7676. I'm happy to add tests in Gutenberg too, but I see there are no unit tests for this part of the codebase in Gutenberg, so I assumed it's better to write them in WordPress directly? What do you think? 🤔


/*
* Add templates registered in the template registry. Filtering out the ones which have a theme file.
Expand Down
Loading