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] Cascade layers: Support layer() function in @import #147354

Closed
BenjaminAster opened this issue Apr 13, 2022 · 8 comments · Fixed by microsoft/vscode-css-languageservice#292
Assignees
Labels
css-less-scss Issues and items concerning CSS,Less,SCSS styling feature-request Request for new features or functionality on-testplan

Comments

@BenjaminAster
Copy link

BenjaminAster commented Apr 13, 2022

With the new CSS cascade layers, it is possible to import a CSS file and directly specify the layer in the @import statement (see specification):

@import url("./foo.css") layer(foo);

However, VSCode shows a syntax error when using this syntax in a CSS file. Cascade layers are supported in all three modern browsers now, so it would be great if VSCode would be updated to recognize this new syntax.

@aeschli aeschli added feature-request Request for new features or functionality css-less-scss Issues and items concerning CSS,Less,SCSS styling help wanted Issues identified as good community contribution opportunities labels Apr 25, 2022
@aeschli aeschli added this to the On Deck milestone Apr 25, 2022
@BenjaminAster
Copy link
Author

@aeschli Are there any updates on this? Cascade layers have now been supported by all modern browsers for over three months, so many people (including me!) already want to use this in production. If the world's most popular code editor shows an error when using a well-supported and not-brand-new feature, most people won't use it. Please prioritize this!

@Pekes317
Copy link

Pekes317 commented Jun 29, 2022

I just want to +1 this feature, also I would assume this would add support also for the the At-Rule.

/* Adds a cascade layer named 'resets' with styles */
@layer resets {
    * {
        margin: 0;
        padding: 0;
    }
}

/* Adds an unnamed layer with styles */
@layer {
    body {
        font-family: system-ui;
        font-size: 14px;
    }
}

/* Declaring cascading order of layers without giving them styles */
@layer resets, framework, settings, layout, utilities;

/* Layers can be nested */
@layer layout {
    main {
        background-color: rebeccapurple;
    }
    @layer composition {
        main {
            display: grid;
            grid-template-columns: repeat(8, 1fr);
        }
    }
}

/* Adds styles to nested layer from top level */
@layer layout.composition {
    .grid-item {
        grid-column: 1 / 4;
    }
}

/* Assigns external stylesheet to a layer */
@import 'bootstrap.css' layer(framework);

@BenjaminAster
Copy link
Author

@Pekes317 The @layer rule is already supported in VSCode (or at least VSCode doesn't show a syntax error). The layer() function in @import however does trigger a syntax error in VSCode, making it practically unusable, so it's the only thing where work needs to be done.

@Pekes317
Copy link

Pekes317 commented Jul 1, 2022

Okay, it must be the linter I'm using because it was getting the proper syntax color and I thought is saw a warning about an unknown At-Rule. If there working being done for the import usage of layers it might worth doing a little discount double on the rest of the layer usage. Well anyway excited for all the CSS Layer stuff.

@Chris-titsus010
Copy link

@Pekes317 I too have the warning saying 'Unknown at rule @layer' but I don't have any linter extension installed.

@BenjaminAster
Copy link
Author

@Chris-titsus010 Just checked, and yes, indeed: I had

"css.lint.unknownProperties": "ignore",
"css.lint.unknownAtRules": "ignore",

in my settings.json. Can recommend to everyone, as VSCode shows a warning for a ton of new CSS properties & at-rules.

Btw, with

"css.validate": false,
"html.validate.styles": false,

you can disable all warnings and errors in all your CSS.

@aeschli aeschli modified the milestones: On Deck, September 2022 Aug 26, 2022
@DavidSouther
Copy link

DavidSouther commented Aug 28, 2022

I am getting css(css-semicolonexpected) with

@import './sanitize.css' layer(reset);
                              ^-- semi-colon expected

@DavidSouther
Copy link

Whoo! Thank you!

@aeschli aeschli added on-testplan and removed help wanted Issues identified as good community contribution opportunities labels Sep 26, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
css-less-scss Issues and items concerning CSS,Less,SCSS styling feature-request Request for new features or functionality on-testplan
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants