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

Updates media query generator function to use CSS range syntax #1833

Draft
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

SohamPatel46
Copy link
Contributor

@SohamPatel46 SohamPatel46 commented Jan 28, 2025

Summary

Fixes #1696

Relevant technical choices

Using CSS range syntax helps eliminate frontend issues where windows are sized sub-pixel dimensions.

This converts media queries from

@media (min-width: 481px) and (max-width: 600px) { 
    #embed-optimizer-a7659db28ecaa36ddee6ae66857dabd8 { min-height: 400px; } 
}

to

@media (480px < width <= 600px) { 
    #embed-optimizer-a7659db28ecaa36ddee6ae66857dabd8 { min-height: 400px; } 
}

The above conversion results in eliminating sub-pixel dimension issues possible between 600px to 601px screen.

@westonruter westonruter added [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) [Type] Enhancement A suggestion for improvement of an existing feature labels Jan 28, 2025
@westonruter
Copy link
Member

Here's a script you can use to update the snapshots once the actual.html files have been generated:

#!/bin/bash
for actual in $( find . -name 'actual.html' ); do
	expected=${actual/actual/expected};
	echo "$actual => $expected"
	mv "$actual" "$expected"
done

There should probably be something like this added to scripts in package.json.

@SohamPatel46
Copy link
Contributor Author

Here's a script you can use to update the snapshots once the actual.html files have been generated:

#!/bin/bash
for actual in $( find . -name 'actual.html' ); do
	expected=${actual/actual/expected};
	echo "$actual => $expected"
	mv "$actual" "$expected"
done

There should probably be something like this added to scripts in package.json.

Hello @westonruter I didn't get your above message. Is this for updating PHP unit tests ?

@westonruter
Copy link
Member

Yes, the unit test failures are due to the HTML snapshots being out for date now that the media query is updated. So you need to move all the actual.html files generated during the unit tests over to replace the expected.html (if indeed the changes are as expected!) That bash script is a way to do so in bulk.

@@ -34,27 +34,27 @@ public function data_to_test_od_generate_media_query(): array {
'mobile' => array(
'min_width' => 0,
'max_width' => 320,
'expected' => '(max-width: 320px)',
'expected' => null,
Copy link
Member

Choose a reason for hiding this comment

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

Why is this null? It should be unchanged.

),
'mobile_alt' => array(
'min_width' => null,
'max_width' => 320,
'expected' => '(max-width: 320px)',
'expected' => null,
Copy link
Member

Choose a reason for hiding this comment

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

Same. This should be unchanged, right?

Comment on lines 52 to 57
'expected' => '(min-width: 601px)',
'expected' => null,
),
'desktop_alt' => array(
'min_width' => 601,
'max_width' => null,
'expected' => '(min-width: 601px)',
'expected' => null,
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider switch to CSS range syntax for media queries in Optimization Detective
2 participants