Skip to content

Commit 74c2ce6

Browse files
committed
Use media query range syntax in sizes attribute
1 parent a9fba2c commit 74c2ce6

File tree

8 files changed

+20
-25
lines changed

8 files changed

+20
-25
lines changed

plugins/image-prioritizer/class-image-prioritizer-img-tag-visitor.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,13 @@ private function compute_sizes( OD_Tag_Visitor_Context $context ): array {
6363
}
6464

6565
if ( $element_max_width > 0 ) {
66-
// TODO: The min-width will need to be adjusted after <https://github.com/WordPress/performance/pull/1839>.
67-
// TODO: Consider reusing od_generate_media_query() here but note the extra parentheses should be removed from its output.
68-
$media_queries = array();
69-
if ( $group->get_minimum_viewport_width() !== 0 ) {
70-
$media_queries[] = sprintf( 'min-width: %dpx', $group->get_minimum_viewport_width() );
71-
}
72-
if ( $group->get_maximum_viewport_width() !== PHP_INT_MAX && $group->get_maximum_viewport_width() !== null ) {
73-
$media_queries[] = sprintf( 'max-width: %dpx', $group->get_maximum_viewport_width() );
74-
}
75-
if ( count( $media_queries ) > 0 ) {
76-
$sizes[] = sprintf( '(%s) %dpx', join( ' and ', $media_queries ), round( $element_max_width ) );
66+
$size = sprintf( '%dpx', $element_max_width );
67+
68+
$media_feature = od_generate_media_query( $group->get_minimum_viewport_width(), $group->get_maximum_viewport_width() );
69+
if ( null !== $media_feature ) {
70+
$size = "$media_feature $size";
7771
}
72+
$sizes[] = $size;
7873
}
7974
}
8075

plugins/image-prioritizer/tests/test-cases/common-lcp-image-and-lazy-loaded-image-outside-viewport-with-fully-populated-sample-data/expected.html

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/image-prioritizer/tests/test-cases/only-mobile-and-desktop-groups-are-populated/expected.html

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/image-prioritizer/tests/test-cases/picture-element-as-lcp-tablet-and-desktop-metrics-missing/expected.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/image-prioritizer/tests/test-cases/picture-element-with-lcp-image-and-fully-populated-sample-data/expected.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/image-prioritizer/tests/test-cases/picture-element-with-source-having-media-attribute/expected.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/image-prioritizer/tests/test-cases/picture-element-with-source-missing-type-attribute/expected.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)