-
Notifications
You must be signed in to change notification settings - Fork 182
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
MPP-3946: Fix warnings for mixed_decls, imports #5176
Conversation
fb05943
to
dda727d
Compare
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.
Code looks good - no blockers. Still need to run the compile and check things out.
// TODO MPP-3946: Fix deprecation warnings in sass 1.80.x | ||
// https://github.com/mozilla/protocol/releases/tag/v18.0.0 |
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.
questgestion (non-blocking): we can remove these lines, right? This TODO
is TODONE
?
// TODO MPP-3946: Fix deprecation warnings in sass 1.80.x | |
// https://github.com/mozilla/protocol/releases/tag/v18.0.0 |
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.
No, there are sass warnings from mozilla-protocol, and the lingering next.js API warning.
padding: $spacing-sm 0; | ||
gap: $spacing-sm; | ||
font-weight: 100; | ||
@include text.title-xs { |
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.
question (non-blocking): TIL sass mixin content blocks. Did you dig into them any deeper than to update the syntax? Do you know if we should file a follow-up to try to utilize the new features of mixin content blocks to improve our sass code in other ways too?
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.
Yes, I think our style definitions should be updated with this in mind. No, I don't think it is worth a ticket, since we would close it as 'not planned' if someone else suggested it. I've thought a bit about it, so I'm writing my blog post here, but feel free to skip it.
We have no experienced front-end developers on staff, and I bet once we hire one, 'clean up style sheets' will be well below other tasks the design team is planning. In the end, we will probably follow the Mozilla Protocol CSS Coding Guide, after they figure out what to do with this change.
The goal with this update was to generate the exact same CSS, with no judgement or re-arrangement. This was mostly because I'm not qualified to judge if the CSS has the same effect, or if there is some gotcha in Chrome vs Firefox vs Vivaldi etc. It was also easiest to judge the output - same hash, same CSS.
This declaration keeps the CSS the same:
.headline {
@include text.title-xs {
display: flex;
align-items: center;
justify-content: center;
padding: $spacing-sm 0;
gap: $spacing-sm;
font-weight: 100;
}
}
The CSS order is 1) the text.title-xs
properties, then 2) the content block properties, then 3) the desktop-width text.title-xs
overrides:
.EmailForwardingModal_headline__VgCSC {
font-size:24px;
font-size:1.5rem;
line-height:1.08;
display:flex;
align-items:center;
justify-content:center;
padding:8px 0;
gap:8px;
font-weight:100
}
@media(min-width:768px) {
.EmailForwardingModal_headline__VgCSC{
font-size:28px;
font-size:1.75rem;
line-height:1.07
}
}
The post Poll Results: How do you order your CSS properties? says the strategies are:
- 45% - Grouped by Type
- 39% - Randomly
- 14% - Alphabetical
- 2% - By line length
Our coding standards doc says:
We follow Protocol's CSS coding guide. See their documentation for additional details.
That document says:
Order declarations alphabetically (from A to Z).
I think the Relay team has not followed that one, because our linters do not enforce it.
If we grouped by type, such as Nicolas Gallagher's idiomatic CSS, which makes the most sense to me (an amateur front-end dev), the sass would be (without the comments):
.headline {
/* No positioning properties */
/* Display and Box Model properties*/
display: flex;
padding: $spacing-sm 0;
gap: $spacing-sm;
align-items: center;
justify-content: center;
/* No color properties */
/* Text properties */
@include text.title-xs {
font-weight: 100;
}
}
This requires knowing what attributes go in what section. I had to use MDN to guess. This would be a good job for a linter.
A hypothetical alphabetical version would need to split the text.title-xs
font declarations from the desktop-size overrides:
.headline {
align-items: center;
display: flex;
@include text.font-title-xs {
font-weight: 100;
}
gap: $spacing-sm;
justify-content: center;
padding: $spacing-sm 0;
@include text.media-desktop-title-xs;
}
This is ugly, requiring developers to remember to include both at-includes, so seems like a bad solution to me.
The marketing organization has a concentration of front-end developers. They have the same mixed-decls
warning. They can address it by changing mozilla-protocol
. They've opened mozilla/protocol#998 to discuss it. I expect that it will be solved in a future release of mozilla-protocol
, and battle-tested in bedrock.
When they have a solution, we can update our code to match it. Our job is to make such that is a one-version update, not several versions like the present case. And maybe have a front-end dev on staff who can contribute to the conversation.
@media screen and #{$mq-md} { | ||
--thumbDiameter: 24px; | ||
} | ||
|
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.
question (non-blocking): Do you know if this block moved for some specific reason? Did the migrator move it?
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.
I manually moved it to get rid of the mixed declaration warning. This code is a better example of the warning than our @include text-title-xs
code, which requires reading code across two repositories. Currently, Dart Sass manually moves the nested @media screen and #{$mq-md} {
code below the top-level properties display: flex
through width: 100%
, but won't in the future.
@@ -45,7 +46,7 @@ | |||
|
|||
.main-img-wrapper { | |||
.main-image { | |||
margin-top: -$layout-lg; // Leave space for image to bleed out of frame | |||
margin-top: -($layout-lg); // Leave space for image to bleed out of frame |
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.
praise: nice catch. did you make this, or the migrator?
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.
I don't know when that changed...
looks at git blame
Ok, the module migrator first changed it to:
@use "~@mozilla-protocol/core/protocol/css/includes/lib" as lib;
.main-img-wrapper {
margin-top: -(lib.$layout-lg); // Leave space for image to bleed out of frame
}
Then I used the --rename
option to change from lib.
to .mp
for mozilla-protocol
:
@use "~@mozilla-protocol/core/protocol/css/includes/lib" as mp;
.main-img-wrapper {
margin-top: -(mp.$layout-lg); // Leave space for image to bleed out of frame
}
Then I used the --rename
option to change from mp.
to *
for mozilla-protocol
, which didn't quite work:
@use "~@mozilla-protocol/core/protocol/css/includes/lib" as *;
.main-img-wrapper {
margin-top: -(*.$layout-lg); // Leave space for image to bleed out of frame
}
so I had to manually (sed
) change it to not treat *
as a namespace:
@use "~@mozilla-protocol/core/protocol/css/includes/lib" as *;
.main-img-wrapper {
margin-top: -($layout-lg); // Leave space for image to bleed out of frame
}
So, generates the same CSS, but maybe should be reverted to the original...
@use "~@mozilla-protocol/core/protocol/css/includes/lib" as *; | ||
@use "../styles/color"; |
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.
question (non-blocking): These Mozilla Protocol @use
statements are identical to the Nebula ones above? Are they supposed to be different? Or is it really the case that the Nebula color variables are in the color
namespace and the Protocol colors are $color-*
variables in the global namespace? I think you mention this in the PR description, but maybe add that explanation to this README.md
too?
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.
yeah, that is not clear to me either. The CSS uses the the actual values (like color:#ffa436
), and the CSS didn't change :broken_record:.
I think it is a separate task to confirm we used the colors we intended to use, since that may change the CSS, and may break E2E screenshot tests. I've opened MPP-3958 for that work, I'll add a reference to the README.
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.
The first time I ran npm run build
, I got warnings but they were for 3rd-party modules - not our code. All runs after the first run finished with no warnings.
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.
A few changes to make:
- Revert change to frontend/src/components/landing/BundleBanner.module.scss
- Add MPP-3958 to README.md
- Add MPP-3959 to
TODO
padding: $spacing-sm 0; | ||
gap: $spacing-sm; | ||
font-weight: 100; | ||
@include text.title-xs { |
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.
Yes, I think our style definitions should be updated with this in mind. No, I don't think it is worth a ticket, since we would close it as 'not planned' if someone else suggested it. I've thought a bit about it, so I'm writing my blog post here, but feel free to skip it.
We have no experienced front-end developers on staff, and I bet once we hire one, 'clean up style sheets' will be well below other tasks the design team is planning. In the end, we will probably follow the Mozilla Protocol CSS Coding Guide, after they figure out what to do with this change.
The goal with this update was to generate the exact same CSS, with no judgement or re-arrangement. This was mostly because I'm not qualified to judge if the CSS has the same effect, or if there is some gotcha in Chrome vs Firefox vs Vivaldi etc. It was also easiest to judge the output - same hash, same CSS.
This declaration keeps the CSS the same:
.headline {
@include text.title-xs {
display: flex;
align-items: center;
justify-content: center;
padding: $spacing-sm 0;
gap: $spacing-sm;
font-weight: 100;
}
}
The CSS order is 1) the text.title-xs
properties, then 2) the content block properties, then 3) the desktop-width text.title-xs
overrides:
.EmailForwardingModal_headline__VgCSC {
font-size:24px;
font-size:1.5rem;
line-height:1.08;
display:flex;
align-items:center;
justify-content:center;
padding:8px 0;
gap:8px;
font-weight:100
}
@media(min-width:768px) {
.EmailForwardingModal_headline__VgCSC{
font-size:28px;
font-size:1.75rem;
line-height:1.07
}
}
The post Poll Results: How do you order your CSS properties? says the strategies are:
- 45% - Grouped by Type
- 39% - Randomly
- 14% - Alphabetical
- 2% - By line length
Our coding standards doc says:
We follow Protocol's CSS coding guide. See their documentation for additional details.
That document says:
Order declarations alphabetically (from A to Z).
I think the Relay team has not followed that one, because our linters do not enforce it.
If we grouped by type, such as Nicolas Gallagher's idiomatic CSS, which makes the most sense to me (an amateur front-end dev), the sass would be (without the comments):
.headline {
/* No positioning properties */
/* Display and Box Model properties*/
display: flex;
padding: $spacing-sm 0;
gap: $spacing-sm;
align-items: center;
justify-content: center;
/* No color properties */
/* Text properties */
@include text.title-xs {
font-weight: 100;
}
}
This requires knowing what attributes go in what section. I had to use MDN to guess. This would be a good job for a linter.
A hypothetical alphabetical version would need to split the text.title-xs
font declarations from the desktop-size overrides:
.headline {
align-items: center;
display: flex;
@include text.font-title-xs {
font-weight: 100;
}
gap: $spacing-sm;
justify-content: center;
padding: $spacing-sm 0;
@include text.media-desktop-title-xs;
}
This is ugly, requiring developers to remember to include both at-includes, so seems like a bad solution to me.
The marketing organization has a concentration of front-end developers. They have the same mixed-decls
warning. They can address it by changing mozilla-protocol
. They've opened mozilla/protocol#998 to discuss it. I expect that it will be solved in a future release of mozilla-protocol
, and battle-tested in bedrock.
When they have a solution, we can update our code to match it. Our job is to make such that is a one-version update, not several versions like the present case. And maybe have a front-end dev on staff who can contribute to the conversation.
@media screen and #{$mq-md} { | ||
--thumbDiameter: 24px; | ||
} | ||
|
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.
I manually moved it to get rid of the mixed declaration warning. This code is a better example of the warning than our @include text-title-xs
code, which requires reading code across two repositories. Currently, Dart Sass manually moves the nested @media screen and #{$mq-md} {
code below the top-level properties display: flex
through width: 100%
, but won't in the future.
@@ -45,7 +46,7 @@ | |||
|
|||
.main-img-wrapper { | |||
.main-image { | |||
margin-top: -$layout-lg; // Leave space for image to bleed out of frame | |||
margin-top: -($layout-lg); // Leave space for image to bleed out of frame |
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.
I don't know when that changed...
looks at git blame
Ok, the module migrator first changed it to:
@use "~@mozilla-protocol/core/protocol/css/includes/lib" as lib;
.main-img-wrapper {
margin-top: -(lib.$layout-lg); // Leave space for image to bleed out of frame
}
Then I used the --rename
option to change from lib.
to .mp
for mozilla-protocol
:
@use "~@mozilla-protocol/core/protocol/css/includes/lib" as mp;
.main-img-wrapper {
margin-top: -(mp.$layout-lg); // Leave space for image to bleed out of frame
}
Then I used the --rename
option to change from mp.
to *
for mozilla-protocol
, which didn't quite work:
@use "~@mozilla-protocol/core/protocol/css/includes/lib" as *;
.main-img-wrapper {
margin-top: -(*.$layout-lg); // Leave space for image to bleed out of frame
}
so I had to manually (sed
) change it to not treat *
as a namespace:
@use "~@mozilla-protocol/core/protocol/css/includes/lib" as *;
.main-img-wrapper {
margin-top: -($layout-lg); // Leave space for image to bleed out of frame
}
So, generates the same CSS, but maybe should be reverted to the original...
@use "~@mozilla-protocol/core/protocol/css/includes/lib" as *; | ||
@use "../styles/color"; |
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.
yeah, that is not clear to me either. The CSS uses the the actual values (like color:#ffa436
), and the CSS didn't change :broken_record:.
I think it is a separate task to confirm we used the colors we intended to use, since that may change the CSS, and may break E2E screenshot tests. I've opened MPP-3958 for that work, I'll add a reference to the README.
frontend/src/styles/globals.scss
Outdated
@@ -22,6 +22,7 @@ a { | |||
/* | |||
Josh's Custom CSS Reset | |||
https://www.joshwcomeau.com/css/custom-css-reset/ | |||
TODO: Try changes from June 2023 and later |
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.
I opened MPP-3959 for this TODO
Copy some of the text-* mixins to a new file /frontend/src/styles/typography.scss Modify the mixins to accept a @content parameter. Use these new mixins to generate the same CSS without the SCSS deprecation warning for mixed declarations: https://sass-lang.com/documentation/breaking-changes/mixed-decls/
This is mostly done with: find . -type f -name '*.scss' | xargs npx sass-migrator module with some custom work to get the build working, and an extra comment to make the generated CSS exactly the same.
Use the namespace 'mp' for main mozilla/protocol lib, and namespace 'mp_forms' for forms library. Converted with: find . -type f -name '*.scss' | xargs npx sass-migrator namespace -r \ "url ~@mozilla-protocol/core/protocol/css/includes/lib to mp; url ~@mozilla-protocol/core/protocol/css/includes/forms/lib to mp_forms"
Order the at-use statements in a consistent way.
f6eb419
to
cf181ba
Compare
Rebased on main to get |
This PR replaces PR #5174.
This PR addresses the Sass 1.80 deprecation warnings about mixed declarations and @import statements. Whenever possible, I used sass-migrator to update the files.
My goals are:
.sass
file needed updates.Some of the changes:
@import
declarations are changed to@use
. This was done bysass-migrator
, which knows the details of variable resolution.@use "~@mozilla-protocol/core/protocol/css/includes/lib" as *;
brings the most commonmozilla-protocol
variables into the global namespace. Replace some alternatives that used thenode_modules
path.@use "~@mozilla-protocol/core/protocol/css/includes/forms/lib" as mp_forms;
for the frequently used forms variables.styles/tokens
becamestyles/color
, since just about everything was a color.styles/color
(wasstyles/tokens.scss
), also remove thecolor-
prefix. This means that the Nebula colors look like.color$light-gray-90
, and the Protocol colors look like$color-light-gray-90
. I'm not sure if one or the other was intended, but now it is a lot clearer which was used where. Did I do it correctly?sass-migrator
made the changes, and the CSS is identical.styles/text
, re-implement the Protocol text@mixins
to take a@content
block.style/README.md
to document these files.Here's an example of the
@mixin
update. This code:becomes:
How to test
Run
cd frontend; npm run build
./frontend/out/_next/static/css
, which means the contents are identical to the previous versions:135df0ac639034c3.css
16a7d9155ef146bc.css
1dd46ac1dae1f8bb.css
4e63d6fb12ba45b3.css
58e1c80c0e503be3.css
644d429e5da963c9.css
7830c6fa1d166113.css
790c7b4cad012f88.css
794f7edf20c99f0e.css
7b7332110014f2b1.css
a98d57fd67295b43.css
bcb82ac07001d0c5.css
c34d49dcc57a01db.css
cf87f152305a1e37.css
f57bb88c3de726c8.css
fce17def8370eee1.css
The
.map
files in the same folder, such as/frontend/out/_next/static/css/135df0ac639034c3.css.map
, have changed because the source file changed.