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 on template name when a plugin registered template matches a default WP theme template #7676

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from

Conversation

Aljullu
Copy link

@Aljullu Aljullu commented Oct 29, 2024

This PR includes the changes that need to be backported from WordPress/gutenberg#66359 into WC core.

Trac ticket: https://core.trac.wordpress.org/ticket/62319


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

github-actions bot commented Oct 29, 2024

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props aljullu, apermo, azaozz.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link

@apermo apermo left a comment

Choose a reason for hiding this comment

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

Looks good to me

@Aljullu Aljullu force-pushed the fix/flash-clicking-template-name branch from db4ea9b to 8ab1d7a Compare November 3, 2024 11:55
@Aljullu
Copy link
Author

Aljullu commented Nov 3, 2024

Thanks for the review, @apermo! Would you mind taking another look? I added a couple of commits that fix some edge cases and add unit tests.

Copy link

@apermo apermo left a comment

Choose a reason for hiding this comment

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

Looking good to me besides that one suggestion, that would make things easier to read imho.

src/wp-includes/block-template-utils.php Outdated Show resolved Hide resolved
Co-authored-by: Christoph Daum <c.daum@me.com>
@Aljullu
Copy link
Author

Aljullu commented Nov 8, 2024

Thanks for the approval, @apermo! I don't have merging rights, is that something you can take care of?

Otherwise, @azaozz, wondering if this is something you can do? Thanks in advance!

@apermo
Copy link

apermo commented Nov 8, 2024

Thanks for the approval, @apermo! I don't have merging rights, is that something you can take care of?

I can't merge either, this happens on the subversion by those with commit right(core commiters), I just reviewed.

@Aljullu Aljullu force-pushed the fix/flash-clicking-template-name branch from 70f64a1 to 8ef61a6 Compare November 26, 2024 13:29
Comment on lines 1182 to 1193
if ( isset( $query['post_type'] ) && ! isset( $template_file['postTypes'] ) ) { // The custom templates with no associated post types are available for all post types.
$candidate = _build_block_template_result_from_file( $template_file, $template_type );
$default_template_types = get_default_block_template_types();
if ( ! isset( $default_template_types[ $candidate->slug ] ) ) {
$query_result[] = $candidate;
}
} elseif (
! isset( $query['post_type'] ) ||
( isset( $query['post_type'] ) && isset( $template_file['postTypes'] ) && in_array( $query['post_type'], $template_file['postTypes'], true ) )
) {
$query_result[] = _build_block_template_result_from_file( $template_file, $template_type );
}
Copy link

Choose a reason for hiding this comment

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

This is definitely better than the one you posted minutes ago.

After checking, I agree that this is equivalent, but I'm unsure wether this is really an improvement. Because the readability in my eyes was better before with single ifs.

Adding a continue; to the first if would likely have the same result. But I'm not convinced about that either.

Maybe moving the comments, and having those better in sight will do the trick here? This would also ask for a comment at the elseif

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! Yeah, I don't have a strong opinion, I prefer the elseif as it makes it clear there is no overlap between the two paths. I added an extra comment in 0cfab7c as you suggested. Please let me know how it looks.

Copy link
Contributor

@azaozz azaozz Nov 26, 2024

Choose a reason for hiding this comment

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

the readability in my eyes was better before with single ifs

I know this is probably getting into a "personal preference" territory, but I tend to agree with @Aljullu that if(){...} elseif(){...} makes it clearer that the two conditionals don't overlap. Also makes this code a very tiny bit faster as the elseif() may not need to be evaluated :)

Co-authored-by: Andrew Ozz <743931+azaozz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants