question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS `min()` and `max()` throw errors for Libsass

See original GitHub issue

Libsass is throwing an error when processing GOV.UK Frontend, as Libsass doesn’t support CSS min() and max() which is used in the width container component.

Specifically, Libsass doesn’t like calc() being used in max() as Libsass tries to process it as a Sass function and can’t because calc() is CSS function for use in the browser. I’ve investigated it in an issue for finder frontend if you’d like more information.

Dart Sass and (ironically) Ruby Sass does support CSS min/max - the things that’s stopping these being used is that there doesn’t seem to be any Rails friendly way of using Dart Sass (without refactoring vast swathes of code so Webpacker can be used) and Ruby Sass is deprecated.

Because there doesn’t seem to be much movement in getting Libsass to have support for CSS min/max, would it be possible to place the notch support behind a flag so it can be turned off? I think the default should be to keep it on, but to have the ability to exclude it with a flag when needed.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

6reactions
injmscommented, Aug 7, 2020

For future reference to anyone who stumbles across this, a solution was found in SassC Rails issue 93.

BUT this turns off CSS compression, so you’ll need to run it through either another CSS compressor in the Rails assets pipeline, or compress it separately.

Relevant bit:

So by adding this to my config/environments/test.rb the problems went away:

# Set a css_compressor so sassc-rails does not overwrite the compressor when running the tests
config.assets.css_compressor = nil

EDIT:

And here’s how to add compression using the Sass gem. Add this to the config file as well:

config.sass.style = :compressed
2reactions
colinrotherhamcommented, Aug 21, 2019

@injms Ah that’s great.

So it sounds like the new Sass min/max feature will cleverly use the native CSS methods, or fall back to the standard Sass ones: https://sass-lang.com/documentation/syntax/special-functions#min-and-max

So one day we can then use native CSS min()/max() in Sass without unquote() 🎉

@nickcolley Sadly it would break the @supports test. To work with Safari on iOS 11+ the units (px) need to be specified otherwise I presume max() evaluates to nothing and doesn’t run.

So this would work for Safari:

margin: unquote("max(0px)")

But, we added calc() into the @supports test because it’s used in the “display cutout” media query itself, so it’s the responsible thing to test for it before we attempt to use it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When Sass and New CSS Features Collide
Shows the `Incompatible units: 'em' and 'vh'` An error when working with different types of units in the min() / max() function. This...
Read more >
Calculations - Sass
If a min() or max() function call is a valid calculation expression, it will be parsed as a calculation. But as soon as...
Read more >
min() in CSS vs. min() in LibSass - Probable Robot
An explanation on why CSS's min function and node-sass do not work ... the min() (and max() ) function and that is what...
Read more >
sass | Dart Package - Pub.dev
min() and max() expressions are once again parsed as calculations as long as they contain only syntax that's allowed in calculation expressions.
Read more >
Changelog - scssphp - GitHub Pages
Fix the handling of CSS variables in rgba() (@stof); Fix the handling of ... Fix the handling of min and max without arguments...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found