-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Server directive processing: Improve how block references are saved #56107
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/experimental/interactivity-api/class-wp-directive-processor.php ❔ lib/experimental/interactivity-api/directive-processing.php ❔ phpunit/experimental/interactivity-api/directive-processing-test.php |
4e57006
to
f165fb7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, Carlos, can you please add these tests:
- Check how many times
process_rendered_html
has been called for different blocks, including one that has a Pattern block. - Check that even if a block with the same
md5
is found, it's not processed if it's not a root block.
One question: Why did you decide not to create a different class than WP_Directive_Processor
? Didn't it make sense?
@@ -19,120 +19,43 @@ | |||
* @return array The parsed block. | |||
*/ | |||
function gutenberg_interactivity_process_directives( $parsed_block, $source_block, $parent_block ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can rename this filter again because it's not processing the directives anymore, only marking the root blocks.
Also, the DocBlock description needs to be updated.
), | ||
); | ||
// Test that root block is not added if there is a parent block. | ||
gutenberg_interactivity_process_directives( $parsed_block, $parsed_block, $parsed_block ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing $parsed_block
three times is confusing.
gutenberg_interactivity_process_directives( $parsed_block, $parsed_block, $parsed_block ); | |
$fake_parent_block = array(); | |
$source_block = $parsed_block; | |
gutenberg_interactivity_process_directives( $parsed_block, $source_block, $fake_parent_block ); |
// Test that a root block is not added if there is already a root block defined. | ||
gutenberg_interactivity_process_directives( $parsed_block_second, $parsed_block_second, $parsed_block_second ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not testing root blocks if you are passing a parent.
// Test that a root block is not added if there is already a root block defined. | |
gutenberg_interactivity_process_directives( $parsed_block_second, $parsed_block_second, $parsed_block_second ); | |
// Test that a root block is not added if there is already a root block defined. | |
gutenberg_interactivity_process_directives( $parsed_block_second, $parsed_block_second, null ); |
Not yet, I think we should keep working on that class and then split it if we consider necessary. |
I'm afraid we cannot do this as a Unit test (is more an e2e test). In order to count how many times a function is called, you need a similar code to this one (provided by Copilot)
You are "duplicating" the class, so using it in different functions won't work. Also, that way, we are testing different things rather than the "root blocks code" of the PR, we would be testing:
We can instead provide an mocked $parent_block just to check that function Hope it helps! |
@luisherranz I've addressed most of the changes requested, thanks for reviewing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect. Thanks @c4rl0sbr4v0!!
phpunit/experimental/interactivity-api/directive-processing-test.php
Outdated
Show resolved
Hide resolved
Has this been backported to Core already? |
Yesss. |
What?
A small refactor to process only root blocks, deleting the root block reference after processing instead of using arrays comparison.
Why?
Although previous version works, this one is easier to read and have better performance.