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

Extending placeholders which have nested media queries leaks placeholder into CSS output #316

Closed
keithamus opened this issue Mar 13, 2014 · 14 comments

Comments

@keithamus
Copy link
Member

keithamus commented Mar 13, 2014

Abstract

Using a placeholder selector, calling a mixin which wraps a media-query, the placeholder selector is leaked into the CSS output.

Detail

Given the following SCSS:

%foo {
    @media screen and (min-width: 300px) {
        max-width: 80%;
    }
}

body {
    @extend %foo;
}

Expected

The output of sass (3.3.1 and 3.2.15)

@media screen and (min-width: 300px) {
  body {
    max-width: 80%; } }

Actual

The output of libsass (actually, node-sass 0.8.3 which is based off of 1122ead)

@media screen and (min-width: 300px) {
  %foo {
    max-width: 80%; } }

As you can see the placeholder %foo should be body but it is not. This is also the same case with multiple selectors extending off of %foo, it still displays %foo instead of the multiple classes that were extended.

I'm quite sure this is only media-query based, I have a reduced test-case with mixins:

@mixin test() {
    @content;
}
%foo {
    @include test() {
        max-width: 80%;
    }
}
body {
    @extend %foo;
}

The output of this is identical in SASS (3.3.1 and 3.2.15) and 1122ead:

body {
  max-width: 80%; }

Further more, multiple mixins also work the same - for example:

@mixin test2() {
    @content
}
@mixin test() {
    @include test2() {
        max-width: 80%;
    }
}
%foo {
    @include test();
}
body {
    @extend %foo;
}

Produces the same output.

@cgarstin
Copy link

cgarstin commented Jul 7, 2014

You can work around this by putting the rules that are inside the mediaquery inside another selector.
E.g change:

%foo {
    @media screen and (min-width: 300px) {
        max-width: 80%;
    }
}

to:

%foo {
    @media screen and (min-width: 300px) {
        &:not(fakeSelector) {
            max-width: 80%;
        }
    }
}

@mattborn
Copy link

mattborn commented Jul 8, 2014

@cgarstin Why have I never seen this?! While this feels like a hack, it does work.

@digitaljhelms
Copy link

Agreed, feels dirty, but awesome workaround for the moment until this is fixed properly. 👍

@mgreter
Copy link
Contributor

mgreter commented Jul 9, 2014

Be aware that nested media rules are a CSS3 feature and not supported by CSS2.

@andres-torres-marroquin

+1 on this issue

@lilymartinez
Copy link

+1

@webinsation
Copy link

Hey guys there is a better cleaner way. Just use this:

%foo {
    @media screen and (min-width: 300px) {
        & {
            max-width: 80%;
        }
    }
}

Hope this helps all you libsassers trying to get it working!

@mgreter
Copy link
Contributor

mgreter commented Jan 6, 2015

This seems to work with latest master! //CC @xzyfer

@xzyfer
Copy link
Contributor

xzyfer commented Jan 6, 2015

Kind of not really @mgreter . The latest master produce the expected output

@media screen and (min-width: 300px) {
  body {
    max-width: 80%; } }

But not the correct output which is an error message.

@xzyfer
Copy link
Contributor

xzyfer commented Jan 6, 2015

Never mind my previous comment I was confusing this issue with #317

@xzyfer
Copy link
Contributor

xzyfer commented Jan 6, 2015

The spec for this is in https://github.com/sass/sass-spec/tree/master/spec/regressions. Do you know what the folder is about @mgreter ?

@mgreter
Copy link
Contributor

mgreter commented Jan 6, 2015

Not really. IMHO I recovered this via perl-libsass when sassc did not yet have the ability to discover passing tests itself. So I just moved that folder from todo!

@xzyfer
Copy link
Contributor

xzyfer commented Jan 17, 2015

I returned the regression specs to their appropriate folders sass/sass-spec#246.

@xzyfer
Copy link
Contributor

xzyfer commented Jan 17, 2015

This is fixed and will be 3.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants