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

Disambiguate XPaths for children of BODY with id, class, or role attributes #1797

Merged
merged 18 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0eeb784
Disambiguate XPaths for children of BODY with id, class, or role attr…
westonruter Jan 13, 2025
286d9cb
Update tests to incorporate new XPaths
westonruter Jan 13, 2025
7810022
Hide diffs for Optimization Detective snapshots
westonruter Jan 13, 2025
d1ad2b3
fixup! Update tests to incorporate new XPaths
westonruter Jan 13, 2025
e37f135
Only use one suitable attribute for disambiguation
westonruter Jan 14, 2025
11f0d0b
Add attributes to elemments not under BODY to show not reflected in X…
westonruter Jan 14, 2025
648eec6
Only capture disambiguating attributes for children of the body to av…
westonruter Jan 14, 2025
385d3bf
Update comments for XPaths to explain disambiguating attribute predic…
westonruter Jan 14, 2025
64659ca
Add test case BODY>DIV which lacks attributes
westonruter Jan 14, 2025
0e2961a
Add missing covers tags
westonruter Jan 14, 2025
7fadaec
Merge branch 'trunk' of https://github.com/WordPress/performance into…
westonruter Jan 21, 2025
c47a613
Include Optimization Detective plugin version in ETag data
westonruter Jan 22, 2025
94843c0
Introduce a transitional XPath format so existing URL Metrics will no…
westonruter Jan 22, 2025
468b6a7
Update test snapshots for embed-optimizer due to XPath change
westonruter Jan 22, 2025
c259b59
Improve docs on XPATH_PATTERN
westonruter Jan 22, 2025
8c526e5
Eliminate boolean arg to get_xpath in favor of new get_stored_xpath m…
westonruter Jan 22, 2025
2922d4c
Replace od_version with xpath_version in ETag data
westonruter Jan 22, 2025
4f2779a
Add tests to ensure the REST API stores the new XPath format
westonruter Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

# Improve highlighting for PHPStan stub files.
*.stub linguist-language=PHP

# Hide diffs for Optimization Detective snapshots.
plugins/*/tests/test-cases/*/expected.html linguist-generated=true
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$elements[] = array_merge(
$element_data,
array(
'xpath' => "/HTML/BODY/DIV/*[{$i}][self::FIGURE]/*[1][self::DIV]",
'xpath' => "/HTML/BODY/DIV[@class='wp-site-blocks']/*[{$i}][self::FIGURE]/*[1][self::DIV]",
)
);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 1,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
),
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]/*[1][self::VIDEO]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]/*[1][self::VIDEO]',
'isLCP' => false,
'intersectionRatio' => 1,
),
array(
'xpath' => '/HTML/BODY/DIV/*[2][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[2][self::FIGURE]/*[1][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 0,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 654 ) ),
),
array(
'xpath' => '/HTML/BODY/DIV/*[2][self::FIGURE]/*[1][self::DIV]/*[1][self::FIGURE]/*[2][self::VIDEO]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[2][self::FIGURE]/*[1][self::DIV]/*[1][self::FIGURE]/*[2][self::VIDEO]',
'isLCP' => false,
'intersectionRatio' => 0,
),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 0,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => true,
'intersectionRatio' => 1,
// Intentionally omitting resizedBoundingClientRect here to test behavior when data isn't supplied.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => true,
'intersectionRatio' => 1,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
foreach ( array_merge( od_get_breakpoint_max_widths(), array( 1000 ) ) as $i => $viewport_width ) {
$elements = array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => true,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 + $i * 100 ) ),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 0,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => true,
'intersectionRatio' => 1,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
foreach ( array_merge( od_get_breakpoint_max_widths(), array( 1000 ) ) as $i => $viewport_width ) {
$elements = array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => true,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 + $i * 100 ) ),
),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 0,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'viewport_width' => 100,
'elements' => array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 1,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => true,
'intersectionRatio' => 1,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
foreach ( array_merge( od_get_breakpoint_max_widths(), array( 1000 ) ) as $viewport_width ) {
$elements = array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => true,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'viewport_width' => 100,
'elements' => array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 0.0,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 0,
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::BOGUS]',
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::BOGUS]',
'isLCP' => false,
'intersectionRatio' => 0.0,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static function () use ( $breakpoint_max_widths ) {
'viewport_width' => $non_desktop_viewport_width,
'elements' => array(
array(
'xpath' => '/HTML/BODY/DIV/*[2][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 0.0,
'intersectionRect' => $outside_viewport_rect,
Expand All @@ -47,7 +47,7 @@ static function () use ( $breakpoint_max_widths ) {
'viewport_width' => 1000,
'elements' => array(
array(
'xpath' => '/HTML/BODY/DIV/*[2][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 0.3,
),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static function () use ( $breakpoint_max_widths ) {
'viewport_width' => $non_desktop_viewport_width,
'elements' => array(
array(
'xpath' => '/HTML/BODY/DIV/*[2][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 0.0,
'intersectionRect' => $outside_viewport_rect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::DIV]',
'isLCP' => true,
),
array(
'xpath' => '/HTML/BODY/DIV/*[3][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[3][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 0.0,
'intersectionRect' => $outside_viewport_rect,
'boundingClientRect' => $outside_viewport_rect,
),
array(
'xpath' => '/HTML/BODY/DIV/*[4][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[4][self::DIV]',
'isLCP' => false,
'intersectionRatio' => 0.0,
'intersectionRect' => $outside_viewport_rect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$test_case->populate_url_metrics(
array(
array(
'xpath' => '/HTML/BODY/DIV/*[1][self::DIV]',
'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::DIV]',
'isLCP' => true,
),
)
Expand Down
Loading
Loading