#61044 closed enhancement (fixed)
Interactivity API: Debug - Warning about Server Directives Processing errors.
Reported by: | cbravobernal | Owned by: | cbravobernal |
---|---|---|---|
Milestone: | 6.6 | Priority: | normal |
Severity: | normal | Version: | 6.5 |
Component: | Interactivity API | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description (last modified by )
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.
I added also notices for cases where the directive is empty, or the namespace is an empty string, an empty object or null.
Change History (16)
This ticket was mentioned in PR #6413 on WordPress/wordpress-develop by @cbravobernal.
8 months ago
#1
- Keywords has-patch added
#2
@
7 months ago
- Milestone changed from Awaiting Review to 6.6
- Type changed from defect (bug) to enhancement
@cbravobernal commented on PR #6413:
7 months ago
#5
I think the messages could be a bit more brief (#6413 (review)) but this is working well generally. Thanks!
@cbravobernal commented on PR #6413:
7 months ago
#6
I'm adding more checks to the SSR processing. Now it will also check that the namespace is not {}
, ""
"empty string", or null
written as a string.
That way it won't cause weird behaviors in the runtime.
#7
@
7 months ago
- Description modified (diff)
- Owner set to cbravobernal
- Status changed from new to assigned
6 months ago
#8
Overall, it looks good and is close to be ready to merge IMO. I left a comment and had the same comments as David above.
Also, it would be good to add a unit test that asserts that the warning message appears correctly in the right circumstances.
It could be something like:
/**
* Tests that the `process_directives` issues a warning when the HTML
* containing directives contains unbalanced tags.
*
* @ticket 61044
*
* @covers ::process_directives
*
* @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
*/
public function test_process_directives_warns_on_unbalanced_tags() {
$this->expectOutputString( 'Interactivity directives failed to process in "" due to a missing "P" end tag' );
$this->interactivity->state( 'myPlugin', array( 'id' => '1231341324' ) );
$this->interactivity->process_directives(
'<div>
<p data-wp-bind--id="myPlugin::state.id">
Hello, world
</div>
</div>
'
);
}
I have tried adding that test but I wasn't able to make it work for some reason:
- The warning message seems to be hidden when using the
@expectedIncorrectUsage WP_Interactivity_API::process_directives_args
annotation.
- When not using the
@expectedIncorrectUsage WP_Interactivity_API::process_directives_args
annotation, I used the$this->expectOutputString()
or$this->expectNoticeMessage()
but they don't seem to be triggered by thedoing_it_wrong()
call in the body ofprocess_directives()
.
@cbravobernal commented on PR #6413:
6 months ago
#9
Overall, it looks good and is close to be ready to merge IMO. I left a comment and had the same comments as David above.
Also, it would be good to add a unit test that asserts that the warning message appears correctly in the right circumstances.
It could be something like:
/** * Tests that the `process_directives` issues a warning when the HTML * containing directives contains unbalanced tags. * * @ticket 61044 * * @covers ::process_directives * * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args */ public function test_process_directives_warns_on_unbalanced_tags() { $this->expectOutputString( 'Interactivity directives failed to process in "" due to a missing "P" end tag' ); $this->interactivity->state( 'myPlugin', array( 'id' => '1231341324' ) ); $this->interactivity->process_directives( '<div> <p data-wp-bind--id="myPlugin::state.id"> Hello, world </div> </div> ' ); }I have tried adding that test but I wasn't able to make it work for some reason:
- The warning message seems to be hidden when using the
@expectedIncorrectUsage WP_Interactivity_API::process_directives_args
annotation.- When not using the
@expectedIncorrectUsage WP_Interactivity_API::process_directives_args
annotation, I used the$this->expectOutputString()
or$this->expectNoticeMessage()
but they don't seem to be triggered by thedoing_it_wrong()
call in the body ofprocess_directives()
.
The only case that makes me think about it would be how would work in a future a test like this with two different warnings. 🤔
6 months ago
#10
The only case that makes me think about it would be how would work in a future a test like this with two different warnings. 🤔
I'm sorry, I don't understand what you mean. Why would there be two different warnings?
@darerodz commented on PR #6413:
6 months ago
#11
I'm sorry, I don't understand what you mean. Why would there be two different warnings?
I think he means that the only warning message the process_directives_args
method outputs is the one for unbalanced tags, and thus, testing the warning message content is not required.
Although the message content changes depending on the tag that caused the error, right? @cbravobernal
@cbravobernal commented on PR #6413:
6 months ago
#12
I think he means that the only warning message the process_directives_args method outputs is the one for unbalanced tags, and thus, testing the warning message content is not required.
I mean that. Maybe in a future, we warn for another cause (I don't know, a directive value processed in that function that requires any specific rule).
We only test that a warning is expected, not which one.
Although the message content changes depending on the tag that caused the error, right?
Yes, the message includes the tag processed when the unbalance variable sets to true.
@cbravobernal commented on PR #6413:
6 months ago
#13
Now we differentiate between SVG and MATH tags and their inner tags with slightly different messages.
All tests has been updated.
https://github.com/WordPress/wordpress-develop/pull/6413/commits/b15ad5f3cb9f6ac1f8249d50908d675cb9673204
6 months ago
#16
Committed with https://core.trac.wordpress.org/changeset/58321.
Trac ticket: https://core.trac.wordpress.org/ticket/61044
Draft PR. Is still work in progress.