Remove building wp_template_parts variation call for frontend#5718
Remove building wp_template_parts variation call for frontend#5718kt-12 wants to merge 35 commits intoWordPress:trunkfrom
Conversation
joemcgill
left a comment
There was a problem hiding this comment.
Left a few questions, but this would be a simple updated if it doesn't cause any unforeseen side effects.
|
Thanks for the latest update @kt-12. Going to break out of the inline thread and respond to your last update here. This approach is a bit better, because it allows variations to only be loaded in What would you think about updating the block registration schema so that you could pass a callable as the Additionally, I think for consistency, we should apply whatever changes we're making for template part variations to other core blocks that register variations dynamically on the server, e.g. Navigation Link, and Post Terms. BTW, this change does seem to have a measurable impact on server response time on the front end, in my local benchmarking, trunk is loading in |
joemcgill
left a comment
There was a problem hiding this comment.
This looks pretty straightforward, @kt-12. I assume we also need to do something similar in the other places where WordPress expects to return a block definition that includes the full set of registered variations, like in WP_REST_Block_Types_Controller or additionally implement as a getter method in WP_Block_Type as @Mamaduka was suggesting here.
|
@kt-12 Some unit tests going fails, The |
|
@joemcgill Implemented the same for Navigation-Link and Post-Term and then did some benchmarking. The following command was run thrice for both Trunk and PR and then Mean (Trunk) and Mean (PR) was obtained
Performance Improvement for TT4 (Tested locally on default homepage)
@Mamaduka This PR is purely based on our findings-based interpretation that the dynamically registered variations were only used inside Furthermore, I have some improvements found on the editor side that could lead to similar performance upgrades on the editor side. However, I don't have the expertise to confirm my findings. Remove inline block schema and replace it with prefetchWe have used the following code at site-editor, widgets-form-blocks, edit-form, wp-customize-widgets The above code preloads the schema for all block types. In the default setup, I found it to add 92 block types with it's variations. Also, the information in the inline script is only used when a person searches for a block or some similar option and is not needed when the page loads (just my understanding based on what I discovered - this could defer). So we don't need all the information in the first load. Proposal
|
Thanks @mukeshpanchal27. Once I have confirmation on the code here I'll raise another PR for GB. At the moment I am confused as to which will part will go in GB and which will stay here, so focusing more on the problem to solve. |
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
….com/10up/wordpress-develop into enhancement/remove-variation-fontend
…into enhancement/remove-variation-fontend
joemcgill
left a comment
There was a problem hiding this comment.
Thanks @kt-12. This is looking promising. I'd love to get feedback from someone like @Mamaduka or @ockham on the general approach.
One important thing to note is that the changes to individual blocks will need to be made in the Gutenberg repo after support for registering variations as a callable is added. I think it makes sense to show the whole change in this PR in the meantime, but we'd likely only commit the changes to get_block_editor_server_block_settings() and the API.
| array( | ||
| 'render_callback' => 'render_block_core_post_terms', | ||
| 'variations' => array_merge( $built_ins, $custom_variations ), | ||
| 'variations' => 'get_variations_core_post_terms', |
There was a problem hiding this comment.
It would be nice to use a consistent naming scheme for all of the variation callbacks in core blocks. Right now you have:
- get_variations_core_navigation_link
- get_variations_core_navigation_link
- build_template_part_block_variations
Personally, I'd go with something like get_block_core_{block_name}_variations which is similar to the consistent render callback render_block_core_{block_name}.
There was a problem hiding this comment.
I was avoiding build_{block name} as the navigation link already had a similar function with a different purpose ->build_variation_for_navigation_link.
I like the get_block_core_{block_name}_variations naming throughout, but we may have to deprecate the function build_template_part_block_variations which is old and can be in use in ways we don't know.
For now, I have made everything build_{block}_block_variations for consistency.
There was a problem hiding this comment.
@joemcgill I have created a draft PR in GB repo - https://github.com/WordPress/gutenberg/pull/56952/files
There are some CS issues which I think someone from GB would be the best person to address.
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
….com/10up/wordpress-develop into enhancement/remove-variation-fontend
spacedmonkey
left a comment
There was a problem hiding this comment.
Changing the type of this property on the block type class feels unwise.
src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php
Outdated
Show resolved
Hide resolved
| array( | ||
| 'render_callback' => 'render_block_core_template_part', | ||
| 'variations' => build_template_part_block_variations(), | ||
| 'variations' => 'build_template_part_block_variations', |
There was a problem hiding this comment.
I think it's okay to have these changes here for now and remove them before merging into the core. Then, we can update the code in the block-library package in a backward compatible way. The Gutenberg plugin supports multiple WP versions.
|
Excellent work, everyone! |
Fix typo Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
New line Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
| ); | ||
|
|
||
| $obtained_variations = $block_type->variations; // access the variations. | ||
| remove_filter( 'get_block_type_variations', array( $this, 'filter_test_variations' ), 10 ); |
There was a problem hiding this comment.
Hooks get reset in WP_UnitTestCase_Base::set_up that runs before each test (link), so no need to clean up filters manually in tests.
🔢 Applies here and throughout.
| $this->assertSameSets( $obtained_variations, $expected_variations, 'The variations obtained from the callback should be filtered.' ); | ||
| } | ||
|
|
||
| public function filter_test_variations( $variations, $block_type ) { |
There was a problem hiding this comment.
Nit: Can you move this function so it's defined prior to all of the to before all of the tests that make use of this filter? Also, adding a docblock here would be terrific.
|
Merged in 57315 |
|
🚨 PHP unit tests are currently failing in the GB repository. It started happening around the time this PR was merged. Example run: https://github.com/WordPress/gutenberg/actions/runs/7590355231/job/20676711107?pr=58031 |
|
@ellatrix Thank you for flagging this. I have found the issue and have a fix for it. I'll push it once I test it out for other scenarios. |
|
Thanks! |
I have added a new ticket for the bug with a detailed description - https://core.trac.wordpress.org/ticket/60309#ticket I have added an initial fix #5915. However, I need to check how my changes affect some operations in |
Trac ticket: https://core.trac.wordpress.org/ticket/59969
Gutenberg PR - WordPress/gutenberg#56952
For TT4, running 500 rounds twice and taking the mean.
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.