-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Interactivity API: Server Directive Processing Refactor #58066
Interactivity API: Server Directive Processing Refactor #58066
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/compat/wordpress-6.5/interactivity-api/class-wp-interactivity-api-directives-processor.php ❔ lib/compat/wordpress-6.5/interactivity-api/class-wp-interactivity-api.php ❔ lib/compat/wordpress-6.5/interactivity-api/interactivity-api.php ❔ phpunit/interactivity-api/class-wp-interactivity-api-directives-processor-test.php ❔ phpunit/interactivity-api/class-wp-interactivity-api-test.php ❔ phpunit/interactivity-api/class-wp-interactivity-api-wp-bind-test.php ❔ phpunit/interactivity-api/class-wp-interactivity-api-wp-class-test.php ❔ phpunit/interactivity-api/class-wp-interactivity-api-wp-context-test.php ❔ phpunit/interactivity-api/class-wp-interactivity-api-wp-interactive-test.php ❔ phpunit/interactivity-api/class-wp-interactivity-api-wp-style-test.php ❔ phpunit/interactivity-api/class-wp-interactivity-api-wp-text-test.php ❔ phpunit/interactivity-api/interactivity-api-test.php ❔ lib/load.php |
Size Change: -82 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
Flaky tests detected in 1954f45. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7643739973
|
lib/compat/wordpress-6.5/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
'@wordpress/interactivity', | ||
gutenberg_url( '/build/interactivity/index.min.js' ), | ||
array(), | ||
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' ) |
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.
Remove this in the WordPress backport.
lib/compat/wordpress-6.5/interactivity-api/interactivity-api.php
Outdated
Show resolved
Hide resolved
lib/compat/wordpress-6.5/interactivity-api/class-wp-interactivity-api-directives-processor.php
Outdated
Show resolved
Hide resolved
lib/compat/wordpress-6.5/interactivity-api/class-wp-interactivity-api-directives-processor.php
Outdated
Show resolved
Hide resolved
PHP unit tests are failing but they are not related: EDIT: This is solved now. |
Sort of a modules question but pertinent to <?php
wp_head();
show_admin_bar( false );
while ( have_posts() ) {
the_post();
$post_content = get_the_content();
$post_content = apply_filters( 'the_content', $post_content );
echo wp_sprintf(
'<div class="prc-platform__iframe__content">%1$s</div>',
$post_content,
);
}
wp_reset_postdata();
wp_footer();
exit(); I was expecting |
Hey Seth. Things should happen in cascade. You should not have to do anything special:
If you are not seeing this behavior, would you mind opening an issue with the steps to reproduce it and pinging me and @sirreal so we can take a look? Thanks! |
lib/compat/wordpress-6.5/interactivity-api/class-wp-interactivity-api-directives-processor.php
Show resolved
Hide resolved
lib/compat/wordpress-6.5/interactivity-api/class-wp-interactivity-api-directives-processor.php
Outdated
Show resolved
Hide resolved
lib/compat/wordpress-6.5/interactivity-api/interactivity-api.php
Outdated
Show resolved
Hide resolved
Thanks for the thorough review, @dmsnell and @c4rl0sbr4v0! 🎉 I've addressed all your feedback, and I think this should be ready to merge now. |
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.
Thanks for all your work on this @luisherranz
As a short note, the phrasing "It only processes one root…" reads a bit awkwardly to me throughout the comments. "Processes only one root…" or "This processes only one root…" in these contexts flows smoother. Just my two cents.
There could probably be more to address here, but nothing seems like it's blocking. Would be nice if you could clarify before merge the expected behavior for non-object JSON values as noted inline, but that's not critical.
lib/compat/wordpress-6.5/interactivity-api/class-wp-interactivity-api.php
Show resolved
Hide resolved
lib/compat/wordpress-6.5/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
lib/compat/wordpress-6.5/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
lib/compat/wordpress-6.5/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
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.
Amazing job done here. Huge props @luisherranz
That's better, thank you. Done in 1954f45.
Done in 6b62b97. Thanks again, folks! I'll wait until the tests pass and I'll merge this 🙂 |
I noticed this PR was merged after I raised the PHP Sync Tracking Issue for WP 6.5 and has changed PHP files that may need backporting to WP Core. I saw it was mentioned in #57959 (comment) so it will need backporting. |
For reference, this is the backport PR and ticket: |
The Interactivity API enables WordPress developers to create dynamic and interactive web experiences with ease using a set of special HTML attributes called directives. Please refer to the [Interactivity API proposal](https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/) for further details. It syncs the changes from the Gutenberg plugin: WordPress/gutenberg#58066. Fixes #60356. Props luisherranz, jonsurrell, swissspidy, westonruter, gziolo. git-svn-id: https://develop.svn.wordpress.org/trunk@57563 602fd350-edb4-49c9-b593-d223f7449a82
The Interactivity API enables WordPress developers to create dynamic and interactive web experiences with ease using a set of special HTML attributes called directives. Please refer to the [Interactivity API proposal](https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/) for further details. It syncs the changes from the Gutenberg plugin: WordPress/gutenberg#58066. Fixes #60356. Props luisherranz, jonsurrell, swissspidy, westonruter, gziolo. Built from https://develop.svn.wordpress.org/trunk@57563 git-svn-id: http://core.svn.wordpress.org/trunk@57064 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The Interactivity API enables WordPress developers to create dynamic and interactive web experiences with ease using a set of special HTML attributes called directives. Please refer to the [Interactivity API proposal](https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/) for further details. It syncs the changes from the Gutenberg plugin: WordPress/gutenberg#58066. Fixes #60356. Props luisherranz, jonsurrell, swissspidy, westonruter, gziolo. Built from https://develop.svn.wordpress.org/trunk@57563 git-svn-id: https://core.svn.wordpress.org/trunk@57064 1a063a9b-81f0-0310-95a4-ce76da25c4cd
What?
This is a whole refactoring of the server directive processing logic in preparation for WP 6.5.
I'll open another PR and a Trac ticket in WordPress Core.
There are also a few small tweaks in the APIs:
wp_interactivity_state( $namespace, $state )
I renamed
wp_initial_state
towp_interactivity_state
because there is now anotherwp_interactivity_config
function to populate the serializable configuration in the server. Also, prefixing it with_interactivity_
made sense to know what state we are referring to.wp_interactivity_config( $namespace, $config )
New function to serialize non-reactive configuration. It's also namespaced.
Internally, I renamed
<script type="application/json" id="wp-interactivity-initial-state">
to<script type="application/json" id="wp-interactivity-data">
because now it contains both the state and config. It serializes the state in thestate
prop and the config in theconfig
prop.wp_interactivity_process_directives( $html )
New function to process the directives found in an HTML string. This should now be suitable for classic themes as well.
Why?
Because the server directive processing will likely be included in WordPress 6.5 and therefore we need to accommodate and prepare the code.
How?
By refactoring everything into a couple of classes: one that controls everything related to the Interactivity API in the server and another one that extends the WP 6.5 version of
WP_HTML_Tag_Processor
to add the ability to get and set content between balanced tags.Testing Instructions
supports.interactivity
set totrue
and with some directives.Additional comments
The
data-wp-each
processor is still missing. I'll work on that on a separate PR.Kudos to @ockham, @dmsnell and @c4rl0sbr4v0 for their previous contributions to this server directive processing ❤️