-
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
Interactivity API: Server Directive Processing #5953
Conversation
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. |
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.
Multiline comments seem to be misaligned, I collected those in this review.
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/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.
I left a few minor suggestions but this looks good in general.
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
Thanks for the review @sirreal! I've addressed the feedback 🙂 |
7aaf308
to
0fe3225
Compare
I've removed the temporary module registration that was included in I've also opened a PR that adds the EDIT: @DAreRodz opened another PR with the |
src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Weston Ruter <[email protected]>
Co-authored-by: Weston Ruter <[email protected]>
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.
Nit: Actually, I suggest consistently using hyphens instead of underscores for CSS class names and style handles.
tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-router-region.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-router-region.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-router-region.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Weston Ruter <[email protected]>
Sorry, I read the other way around 🤦♂️ Ok, this should be ready 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.
🎉
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/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.
Just a couple additional nits on method naming.
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Pascal Birchler <[email protected]>
Co-authored-by: Weston Ruter <[email protected]>
Co-authored-by: Pascal Birchler <[email protected]>
Committed with https://core.trac.wordpress.org/changeset/57563. Thank you everyone for all help to make that happen 🎉 |
Thanks, Greg! ❤️ A huge kudos to @DAreRodz, @SantosGuillamot and @c4rl0sbr4v0 for shaping the Interactivity API with me, to @ockham for the initial work on the server directive processing logic, to @dmsnell for his support with the HTML APIs, to @gziolo, @mtias and @youknowriad for their continued support and feedback on the APIs, to @westonruter, @felixarntz and @swissspidy for their support and their help shaping this for WP Core, and finally to @Poliuk and @rmartinezduque for their under the scenes work to make this API a reality. I'm sure I forget people, but thanks to everyone for your support of this initiative. This is just the beginning, but I hope it adds value to all the WordPress users for many years to come 🙂 |
Trac ticket: https://core.trac.wordpress.org/ticket/60356
This PR backports the Server Directive Processing of the new Interactivity API for WordPress.
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 for further details.
This API processes the interactivity directives embedded within HTML content and transforms the markup in the server, seamlessly merging the server-rendered markup with the client-side interactivity to guarantee that:
API
wp_interactivity_state( $store_namespace, $state )
Sets or gets the initial state of an interactivity store.
This state is used during the server directive processing and then is serialized and sent to the client as part of the interactivity data to be recovered during the hydration of the client interactivity stores.
Once the user starts interacting with the page, the actions contained in the stores will update this
state
, and the Interactivity API runtime will transform the markup accordingly.wp_interactivity_config( $store_namespace, $config )
Sets or gets configuration for an interactivity store.
This configuration is also serialized to the client, but it's static information about the page/site (it's not reactive).
wp_interactivity_process_directives( $html )
Processes directives within HTML content, updating the markup where necessary.
Filter:
wp_interactivity_process_directives_of_interactive_blocks
This function hooks into WordPress's block rendering pipeline, identifying the outermost interactive block in a hierarchy and marking it for directive processing after rendering. Subsequent nested blocks are ignored during this pass because their output is included in the root block's render. Once the root block's HTML is processed, the markup is transformed and ready to be sent to the client.
Feedback
Please share your thoughts, potential use cases, or any other input that could help us refine and enhance this feature. Use the Trac ticket or this pull request for discussions.
Thank you! 🙏
Remaining tasks
The code here is ready for initial reviews, but I'd like to finish a few tasks before considering it complete:
wp_register_script_modules
calls.data-wp-each
.data-wp-each
gutenberg#58498data-wp-router-region
.data-wp-interactive="myPlugin"
.data-wp-context
.I'll work on them and report my progress here.
Follow-ups
This list of tasks is not as high priority and can be done in follow-ups: