openstyles / stylus

Stylus - Userstyles Manager
https://add0n.com/stylus.html
GNU General Public License v3.0
5.45k stars 305 forks source link

[Bug] Applying on all pages when using `@preprocessor stylus` #1819

Open zenstorage opened 2 months ago

zenstorage commented 2 months ago

Bug Report

Bug Description

When using the Stylus preprocessor with nested Media Queries, the styles are applied to all pages.

Screenshots

image

example.net: image

example.com: image

CSS Code

/* ==UserStyle==
@name           example.com
@namespace      github.com/openstyles/stylus
@version        1.0.0
@description    A new userstyle
@author         Me
@preprocessor   stylus
==/UserStyle== */

@-moz-document domain("example.com") {
        /* Only in example.com */
    h1 {
        border: 3px solid yellow;
    }

    @media (min-width: 600px) {
        /* Only in example.com */
        p {
            border: 3px solid blueviolet;
        }
        @media (min-height: 600px) {
            /* Styles above are applied to all pages */
            * {
                border: 3px solid red;
            }
        }
    }
}

System Information

Additional Context

tophf commented 2 months ago

It's a bug in stylus-lang @preprocessor. Its development is apparently abandoned and it has so many bugs that I wonder if we should remove it altogether...

zenstorage commented 2 months ago

Good to know, unfortunately it is abandoned, it has the most functions to use

tophf commented 2 months ago

Try workarounds in this list and if none helps, try reporting the problem in https://github.com/stylus/stylus/issues/

zenstorage commented 2 months ago

Thanks, I will try

pabli24 commented 2 months ago

For some reason this

@-moz-document domain("example.com") {
    @media (min-width: 10px) {
        p {
            color: #000
        }
        @media (min-height: 20px) {
            p {
                color: #fff
            }
        }
    }
}

compiles to

@-moz-document domain("example.com") {
@media (min-width: 10px) {
    p {
      color: #000;
    }
}
}
@media (min-width: 10px) and (min-height: 20px) {
  p {
    color: #fff;
  }
}

The easiest solution would be to not nest @media

@-moz-document domain("example.com") {
    @media (min-width: 10px) {
        p {
          color: #000
        }
    }
    @media (min-width: 10px) and (min-height: 20px) {
      p {
        color: #fff
      }
    }
}

I also noticed that more nesting "fixes" it :D

@document domain("example.com") {
    & {
        @media (min-width: 10px) {
            p {
                color: #000
            }
            @media (min-height: 20px) {
                p {
                    color: #fff
                }
            }
        }
    }
}