Skip to content
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: Add debug notice for SSR #6413

Open
wants to merge 13 commits into
base: trunk
Choose a base branch
from

Conversation

cbravobernal
Copy link

@cbravobernal cbravobernal commented Apr 19, 2024

Trac ticket: https://core.trac.wordpress.org/ticket/61044

This PR aims to improve the developer experience of the Interactivity API server directives processing.
Right now, the SSR won't work if there is any directive inside a SVG or MATHML tag. Or the HTML is unbalanced (there is some closer tag missing).

This PR adds a warning in those cases, if the developer is in debug mode.

Screenshot 2024-04-22 at 12 50 48

Screenshot 2024-04-22 at 12 51 25

Screenshot 2024-04-22 at 12 51 48


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.

Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@cbravobernal cbravobernal marked this pull request as ready for review April 22, 2024 15:19
Copy link

github-actions bot commented Apr 22, 2024

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props cbravobernal, jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an annotation that I believe is the preferred way to implement these tests:

/**
 * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
 */

@@ -639,7 +660,8 @@ public function test_process_directives_changes_html_if_contains_svgs() {
</header>
';
$processed_html = $this->interactivity->process_directives( $html );
$p = new WP_HTML_Tag_Processor( $processed_html );
$this->setExpectedIncorrectUsage( 'WP_Interactivity_API::process_directives_args' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is available as an annotation. Add this to the tests that are expected to fail and all the changes to implement this tracking can be removed:

	 * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args

Copy link
Member

@sirreal sirreal left a 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 notes but generally I think this is in a good place. I think the messages could be improved to be a bit more brief. I also think it might be helpful to include the interactivity namespace so that it's easier to locate the problem if there are many different interactive regions, what do you think?

For SVG/MATH:

Interactivity directives were detected on an incompatible %s tag when processing {{ namespace }}. These directives will be ignored.

For unbalanced (this is always due to a start tag without an end tag, right?):

Interactivity directives failed to process in {{ namespace }} due to a missing %s end tag.

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the messages could be a bit more brief (#6413 (review)) but this is working well generally. Thanks!

@cbravobernal
Copy link
Author

I think the messages could be a bit more brief (#6413 (review)) but this is working well generally. Thanks!

Done in 4b78690

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants