From dc05ff0fd67f3a10195aa1b7f1bbd4c5ac7c8a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 1 Mar 2025 12:11:48 +0100 Subject: [PATCH] Downgrade Sass to version 1.77.5 In commit 64bcedc8b, we upgraded Sass from version 1.70 to version 1.80. However, since then we've noticed a couple of inconvenient things. First, we're getting some deprecation warnings when compiling the assets, related to a usage of `map-has-key` in Foundation which is deprecated since Sass 1.80. Even with the `quiet_deps` flag, these warnings aren't silenced. Second, version 1.79 changed the way color functions work [1]. In particular, functions like `color.adjust` or `darken` would now generate RGB colors that include float numbers [2]. Browser support for float values in RGB colors is about 98% at the time of writing [3], meaning some browsers that are at least 5 or 6 years old will not render these colors, sometimes resulting in white text over a white background, which is of course impossible to read. Finally, we get some deprecation warnings in our code when we remove the `quiet_deps` flag, caused by the breaking change in mixed declaration [4] from version 1.77.7 [5]. This warning is tricky; consider the following code: ``` @mixin normal-selection { &::selection, *::selection { @include background-with-text-contrast($brand, brand, $check-invert-selection: false); } } .button.hollow { @include normal-selection; border: 1px solid; } ``` In this scenario, since normal-selection is a mixin that generates a nested rule, we're doing a declaration after a nested rule, which is now deprecated. The situation gets even more complicated when we define mixins that have both nested rules and rules that apply to the element itself. Currently, we sometimes include a mixin and then override some of the properties the mixin defines, but we wouldn't be able to do so if we can't define properties after including the mixin. Right now, the solution seems to be adding `& { }` selectors after including a mixin, like this: ``` .button.hollow { @include normal-selection; & { border: 1px solid; } } ``` Which is incredibly cumbersome. So, for now, we're downgrading to version 1.77.5 (we would downgrade to version 1.77.6, but the sass-embedded gem skipped that version). That version was released in June 2024, so it isn't very old yet. In the future, we'll see what to do about the issues mentioned above, since we'll have to upgrade at some point. Note we're removing the `silence_deprecations` flag because Sass 1.77 doesn't raise warnings about using `import`. [1] https://sass-lang.com/documentation/breaking-changes/color-functions/ [2] https://sass-lang.com/documentation/modules/color/#adjust [3] https://caniuse.com/mdn-css_types_color_rgb_float_values [4] https://sass-lang.com/documentation/breaking-changes/mixed-decls/ [5] https://sass-lang.com/documentation/js-api/interfaces/deprecations/#mixed_decls --- Gemfile | 2 +- Gemfile.lock | 10 +++++----- config/initializers/sass.rb | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index c0f2a20c9..4b699cd3c 100644 --- a/Gemfile +++ b/Gemfile @@ -49,7 +49,7 @@ gem "redcarpet", "~> 3.6.0" gem "responders", "~> 3.1.1" gem "rinku", "~> 2.0.6", require: "rails_rinku" gem "ros-apartment", "~> 2.11.0", require: "apartment" # Remove ConnectionHandling monkey patch when upgrading -gem "sassc-embedded", "~> 1.80.1" +gem "sassc-embedded", "~> 1.77.5" gem "sassc-rails", "~> 2.1.2" gem "savon", "~> 2.15.1" gem "sitemap_generator", "~> 6.3.0" diff --git a/Gemfile.lock b/Gemfile.lock index 9446eeef4..355a66885 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -593,13 +593,13 @@ GEM capistrano (~> 3.0) sshkit (>= 1.2) safely_block (0.4.1) - sass-embedded (1.80.4) - google-protobuf (~> 4.28) + sass-embedded (1.77.5) + google-protobuf (>= 3.25, < 5.0) rake (>= 13) sassc (2.4.0) ffi (~> 1.9) - sassc-embedded (1.80.1) - sass-embedded (~> 1.80) + sassc-embedded (1.77.5) + sass-embedded (~> 1.77) sassc-rails (2.1.2) railties (>= 4.0.0) sassc (>= 2.0) @@ -794,7 +794,7 @@ DEPENDENCIES rubocop-rspec (~> 3.4.0) rubocop-rspec_rails (~> 2.30.0) rvm1-capistrano3 (~> 1.4.0) - sassc-embedded (~> 1.80.1) + sassc-embedded (~> 1.77.5) sassc-rails (~> 2.1.2) savon (~> 2.15.1) selenium-webdriver (~> 4.25.0) diff --git a/config/initializers/sass.rb b/config/initializers/sass.rb index ff9946cdc..3760b32e5 100644 --- a/config/initializers/sass.rb +++ b/config/initializers/sass.rb @@ -1,10 +1,9 @@ -# TODO: Remove quiet_deps once we upgrade Foundation and Font Awesome, -# and remove silence_deprecations once we migrate away from Sass @import rules, -# which will be removed in Dart Sass 3.0.0. +# TODO: we could remove it once we upgrade Font Awesome, although +# we might need to add it again if we upgrade Sass SassC::Engine.class_eval do alias_method :original_initialize, :initialize def initialize(template, options = {}) - original_initialize(template, options.merge(quiet_deps: true, silence_deprecations: [:import])) + original_initialize(template, options.merge(quiet_deps: true)) end end