-
Notifications
You must be signed in to change notification settings - Fork 103
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
Fix logic for seeking during optimization loop to prevent emitting seek() notices #1376
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@@ -309,6 +308,79 @@ public function data_provider_test_od_optimize_template_output_buffer(): array { | |||
', | |||
), | |||
|
|||
'many_images' => array( |
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.
😎
* @return int Count of seek() calls. | ||
*/ | ||
public function get_seek_count(): int { | ||
return $this->seek_count; |
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.
nice!
static function () { | ||
$tags = array(); | ||
for ( $i = 1; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS + 1; $i++ ) { | ||
$tags[] = sprintf( '<img data-od-xpath="/*[1][self::HTML]/*[2][self::BODY]/*[%d][self::IMG]" src="https://example.com/foo.jpg" alt="Foo" width="1200" height="800" loading="lazy">', $i ); |
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.
spiffy
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.
good catch & fix!
Summary
As observed by @thelovekesh, Optimization Detective is causing many notices to show up in the error log:
This is due to my incorrect implementation of the optimization loop, where it is seeking back to the current tag after calling a visitor, even if that visitor never seeked (sought?) or called
next_tag()
. I guess HTML Tag Processor should actually short-circuit if the bookmark being seeked to is the same as the current cursor (bytes_already_parsed
). In any case, we can work around this by exposing theseek_count
with a getter and only seeking back to the current tag if the seek count has increased and doing the same by counting the number of times thatnext_token()
was called and seeking back if it was incremented.This also fixes a bug with a translation string I noticed.
optimization-detective
Important
Stable tag change: 0.4.0 → 0.4.1
svn status
:svn diff