-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Editor: Move Interactivity directives processing to WP_Block class #6331
Editor: Move Interactivity directives processing to WP_Block class #6331
Conversation
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 Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
867ef75
to
ff14587
Compare
! empty( $this->block_type->supports['interactivity']['interactive'] ) | ||
) | ||
) { | ||
$root_interactive_block = $this; |
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.
Would be more efficient to add an extra attribute to parsed_block than to compare the entire block?
I remember that the problem comparing $parsed_block attribute in layout has been fixed.
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.
But this change would require some testing, so better leave for a follow-up PR.
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.
Objects are stored and compared by reference, right? How would be any alternative more efficient in that case?
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.
Checking a object property is more performant than checking the entire object, right?
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.
Can you share a code example to illustrate the idea?
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.
@cbravobernal, I think you're confusing arrays with objects here in PHP.
The problem lies in arrays, as PHP doesn't compare them by reference, and instead compares the entire array. In this case, checking a property of the array is more performant than checking the entire array.
However, in the case of objects, they are instances of a class and are compared by reference. So there's no performance problem.
Is that correct, @gziolo?
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.
@cbravobernal, I think you're confusing arrays with objects here in PHP.
Yep, as we were comparing arrays back then in $parsed_block
if I remember correctly.
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.
Yes, but that's no longer the case, right? So we no longer have that problem.
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.
Great work Greg.
Tested and works perfectly. It also is cleaner and easier to follow than the other approach.
We are also saving tons of filters on the process.
Added a filter to be able to enable/disable server directives processing and an unit test for it. |
tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php
Outdated
Show resolved
Hide resolved
Neccessary for the planned changes in WordPress core: WordPress/wordpress-develop#6331.
I documented the new filter. I renamed it to I also opened WordPress/gutenberg#62095 to have the fix in place to Gutenberg at the time of the commit so E2E tests continue to pass. |
Committed with https://core.trac.wordpress.org/changeset/58234. |
Neccessary for the planned changes in WordPress core: WordPress/wordpress-develop#6331. Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
Neccessary for the planned changes in WordPress core: WordPress/wordpress-develop#6331. Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
Since this filter is used to control whether the blocks are processed or not, wouldn't it be better to include the word "blocks" in the name of the filter? Otherwise, people can think it is related to the Like |
It also could be moved to the body of |
What is the main use of this filter? Is it so that plugins can disable the Server Directive Processing for some reason, or is it so that Gutenberg can replace it with a more updated version? |
We have e2e tests that disable the Server Directive Processing. That's the only one that come to my mind right now. Gutenberg crashed and we had to choose between 2 options:
|
Ok, thanks Carlos 🙂 I don't have a strong opinion on whether we should rename the filter or also include the processing of the |
I think disabling all SSR would make more sense than only in blocks, right? |
Neccessary for the planned changes in WordPress core: WordPress/wordpress-develop#6331. Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
Trac ticket: https://core.trac.wordpress.org/ticket/61185#ticket
Testing performance with TT4 and homepage:
Before (trunk): wp-total (median) 55.59 ms
After (branch): wp-total (median) 55.18 ms
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.