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

report: use container queries for responsive design in DevTools #16342

Merged
merged 5 commits into from
Feb 26, 2025

Conversation

dvangonen
Copy link
Contributor

@dvangonen dvangonen commented Feb 16, 2025

Summary

This is a fix of broken lighthouse layout in Chrome DevTools.

You can't actually see this problem in standalone version of Lighthouse. Because there are @media queries, which apply proper stylings to all elements based on Viewport.

But you can't rely on Viewport if you've integrated into Chrome DevTools.
So this PR leverages a new feature available - css container queries, which helps apply the same styles as @media queries, but to the container itself.

Related Issues/PRs

Issue

@dvangonen dvangonen requested a review from a team as a code owner February 16, 2025 20:06
@dvangonen dvangonen requested review from adamraine and removed request for a team February 16, 2025 20:06
Copy link

google-cla bot commented Feb 16, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@dvangonen dvangonen changed the title Add container queries for responsive design in Chrome DevTools Report: add container queries for responsive design in Chrome DevTools Feb 16, 2025
@dvangonen dvangonen changed the title Report: add container queries for responsive design in Chrome DevTools report: add container queries for responsive design in Chrome DevTools Feb 16, 2025
@@ -225,6 +225,32 @@
}
}

@container lh-container (max-width: 480px) {
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we just replace the @media queries with @container queries?

Copy link
Contributor Author

@dvangonen dvangonen Feb 19, 2025

Choose a reason for hiding this comment

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

I left media queries as a fallback for older browsers.. @container is available since 2023 across major browsers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should keep them both for better compatibility

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. In that case can you add some TODO comments above the media queries about removing them and link to the bug #16332.

We can circle back to this once @container queries hit widely available in baseline.

Copy link
Member

@adamraine adamraine left a comment

Choose a reason for hiding this comment

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

Overall LGTM but one missing comment I think

@@ -1701,6 +1789,13 @@
}
}
Copy link
Member

@adamraine adamraine Feb 20, 2025

Choose a reason for hiding this comment

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

Comment for the media query above here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

@dvangonen dvangonen Feb 24, 2025

Choose a reason for hiding this comment

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

So, it's looking pretty nice now. Can we merge this pr?

@dvangonen
Copy link
Contributor Author

I rebuild here with yarn build-all. Tests should pass now.

@@ -141,6 +165,15 @@ body {
}
}

@container lh-container (min-width: 636px) {
Copy link
Member

Choose a reason for hiding this comment

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

These are a separate set of styles that will not be inside the lh-container container div and won't be used in DevTools.

I think we should revert the changes in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's right

@adamraine adamraine changed the title report: add container queries for responsive design in Chrome DevTools report: use container queries for responsive design in DevTools Feb 26, 2025
@adamraine adamraine merged commit 7d919b8 into GoogleChrome:main Feb 26, 2025
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants