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

CSS variable (custom property) with fallback as nothing compiles to no fallback #3245

Closed
3 tasks
yairEO opened this issue Jan 10, 2022 · 4 comments · Fixed by #3336 or sass/dart-sass#1723
Closed
3 tasks
Assignees
Labels
bug Something isn't working CSS compatibility Support the CSS spec

Comments

@yairEO
Copy link

yairEO commented Jan 10, 2022


https://www.sassmeister.com/gist/64d412cd7fcc65d2fd09d10c89cb2e0f

div {
    transform: translate(100px) var(--transform-y, );
}

The , at the end is valid CSS and is no mistake and should not be removed after compiling.


Read more about the use-case in this article:

https://css-tricks.com/optional-custom-property-values-trick/

W3 ref:

https://www.w3.org/TR/css-variables-1/#using-variables

In an exception to the usual comma elision rules, which require commas to be omitted when they’re not separating values, a bare comma, with nothing following it, must be treated as valid in var(), indicating an empty fallback value.

@nex3 nex3 transferred this issue from sass/dart-sass Jan 12, 2022
@nex3 nex3 added bug Something isn't working CSS compatibility Support the CSS spec requires deprecation Blocked on a deprecation cycle and removed requires deprecation Blocked on a deprecation cycle labels Jan 12, 2022
@nex3
Copy link
Contributor

nex3 commented Jan 12, 2022

At first I thought this was really bad: the spec parses the second argument as a <declaration-value> which allows essentially any string, but Sass has historically parsed it as a SassScript value, which means that we'd have to do a deprecation process to become CSS-compatible. Fortunately, I think we can dodge that bullet: unlike custom property values (whose behavior we did have to deprecate), var() functions can only be used in CSS properties rather than being directly accessible to JavaScript. This means that while arbitrary values are valid syntax for the second argument, only "normal" CSS values are actually meaningful.

The only exception to this is var() functions that are called in custom property values, which are resolved before the values are made accessible to JavaScript and as such do make their second arguments directly accessible. Fortunately, those are already parsed as <declaration-value>s by virtue of the fact that they're already in custom property values.

The upshot of all this is that we can get away with simply adding special-case logic for an empty second argument without having to deprecate the way we parse the second argument when it does exist.

@yairEO
Copy link
Author

yairEO commented Apr 27, 2022

Hi @nex3 - any news? :)

@nex3
Copy link
Contributor

nex3 commented May 2, 2022

When there's news, we'll update this issue. If you'd like the process to move more quickly, please feel free to contribute a spec update.

@nex3 nex3 self-assigned this Jun 16, 2022
nex3 added a commit that referenced this issue Jun 16, 2022
This sets the stage for modifying it to fix #3245
nex3 added a commit that referenced this issue Jun 16, 2022
This sets the stage for modifying it to fix #3245
nex3 added a commit that referenced this issue Jun 16, 2022
This sets the stage for modifying it to fix #3245
nex3 added a commit that referenced this issue Jun 16, 2022
This sets the stage for modifying it to fix #3245
nex3 added a commit that referenced this issue Jun 16, 2022
This sets the stage for modifying it to fix #3245
nex3 added a commit that referenced this issue Jun 16, 2022
nex3 added a commit that referenced this issue Jun 16, 2022
nex3 added a commit to sass/sass-spec that referenced this issue Jun 16, 2022
nex3 added a commit to sass/dart-sass that referenced this issue Jun 16, 2022
nex3 added a commit to sass/sass-spec that referenced this issue Jun 16, 2022
@nex3 nex3 reopened this Jun 16, 2022
@nex3
Copy link
Contributor

nex3 commented Jun 16, 2022

This is now out for review as a fast-track proposal in #3338. I'll leave it open until Tuesday unless anyone has any objections or suggestions.

nex3 added a commit that referenced this issue Jun 21, 2022
nex3 added a commit to sass/sass-spec that referenced this issue Jun 21, 2022
nex3 added a commit to sass/dart-sass that referenced this issue Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CSS compatibility Support the CSS spec
Projects
None yet
2 participants