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.

Property with null value is not omitted if it has !important flag.

See original GitHub issue

Given the following code:

// null value example
$some-value: null !default;

.class {
  color: $some-value;
  color: $some-value !important;
}

The first color property is omitted since it’s value is null. The second is not omitted and invalid CSS is outputted: color: !important;. I’d expect the !important flag not to matter when the value is null and both properties to be omitted, but it’s not that clear to me what the expected result should be from the null page.

This can be worked around by using an if rule around the property using important and checking for the variable, so it’s not a huge issue.

Playground: https://www.sassmeister.com/gist/b04fe1d7b7902c62593b2afac2516e26

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
connorskeescommented, Dec 17, 2021

if you need a workaround to get rid of the errors, you can assign to a variable before returning,

@function important-if-not-null($value) {
    @if $value {
        $return: $value !important;
        @return $return;
    } @else {
        @return null;
    }
}

$some-null-value: null;
$some-non-null-value: foo;

a {
    color: important-if-not-null($some-null-value);
    color: important-if-not-null($some-non-null-value);
}
0reactions
bcbcbcbcbclcommented, Dec 18, 2021

@connorskees Thank you so much, really appreciate it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does it mean for a property to be [Required] and nullable?
The reason for making a property nullable and marked with the [Required] attribute is to protect against under-posting attacks.
Read more >
Flag Null Values in your Datasets - salesforceblogger.com
Well, if you group by a dimension containing null value those records with null values are omitted from the result, which means that...
Read more >
Use empty string, null or remove empty property in API request ...
While most modern serializers have optional fields, omitting nulls from the response is not always a good idea, because it may introduce ...
Read more >
Property flags and descriptors - The Modern JavaScript Tutorial
Until now, a property was a simple “key-value” pair to us. ... otherwise not listed. configurable – if true , the property can...
Read more >
Terraform Optional Variables and Attributes — Using Null and ...
This is because the variables could cause the resource arguments to be triggered with expected values even though you set nonsense default values...
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