Skip to content

[css-cascade] When an import rule fails to load or has an unsatisfied condition, does the layer still count? #6776

Closed

Description

@xiaochengh

Consider @import rules below:

@import url(url-not-found.css) layer(A);
@import url(sheet.css) layer(B) not all;
@import url(sheet.css) layer(C) supports(display: invalid-value);

While these are valid but ineffective imports, do the layer declarations still count (and hence affect the global layer ordering)? The current spec seems unclear about it.

I suppose for conditional imports whose conditions evaluate to false, the layer declarations should not count, because nested @layer rules inside false media/supports rules do not count.

I'm unsure about imports that fail to load, though. We may count the layer for a stable global layer ordering, or do not counter the layer to be consistent with media/supports conditions. Either as a resolution will be fine for me.

Activity

  1. changed the title [-][css-cascade] When an import rule fails to load or isn't enabled, does the layer still count?[/-] [+][css-cascade] When an import rule fails to load or has an unsatisfied condition, does the layer still count?[/+] on Oct 28, 2021
  2. mirisuzanne commented on Oct 28, 2021

    @mirisuzanne
    Contributor

    The way I understand the spec, we should already have implied answers to all of these, which we can clarify if we need to:

    • layer A is established, but empty (stable layer order)
    • layers B and C are not established since the global queries are false
  3. tabatkins commented on Oct 29, 2021

    @tabatkins
    Member

    The precise interleaving of layers and conditions in the import rule isn't specified, so we should be clearer about this, but I agree with @mirisuzanne on the details of how each case should work. The mental model should be that a layer is wrapped around the contents of the import (even if they're empty due to a load failure), and a condition is wrapped around the whole thing:

    @import url(...) layer(foo) (condition: bar);
    
    /* equivalent to */
    
    @media (condition: bar) {
     @layer foo {
       ...import contents...
     }
    }
  4. added 3 commits that reference this issue on Nov 10, 2021
  5. added a commit that references this issue on Nov 11, 2021
  6. added a commit that references this issue on Nov 15, 2021
  7. mirisuzanne commented on Nov 16, 2021

    @mirisuzanne
    Contributor

    Agenda+ to get this spec change approved by the group.

  8. added a commit that references this issue on Nov 16, 2021
  9. css-meeting-bot commented on Nov 17, 2021

    @css-meeting-bot
    Member

    The CSS Working Group just discussed [css-cascade] When an import rule fails to load or has an unsatisfied condition, does the layer still count?, and agreed to the following:

    • RESOLVED: Accept proposal
    • RESOLVED: Republish css-cascade-5
    The full IRC log of that discussion <fantasai> Topic: [css-cascade] When an import rule fails to load or has an unsatisfied condition, does the layer still count?
    <fantasai> github: https://github.com//issues/6776
    <fantasai> miriam: A few questions in here
    <fantasai> miriam: All related to establishing layers inside of an @import statement.
    <fantasai> miriam: One question is what to do if the import fails
    <fantasai> miriam: other question is what to do if the conditions of the import don't match
    <fantasai> miriam: consensus in the thread was that we should conceptualize this to "layer is wrapped around contents of the import, even if empty due to failure, and condition is wrapped around the whole thing"
    <fantasai> miriam: We added language to spec to express it that way
    <fantasai> miriam: layer is still added to layer order if import fails
    <fantasai> miriam: but not added if the conditions don't match
    <fantasai> miriam: that matches the behavior of if you had import inside of layer inside of condition
    <fantasai> miriam: wanted to check with WG if this is acceptable
    <fantasai> jensimmons: Makes a lot of sense from authoring point of view
    <fantasai> +1 from me
    <fantasai> RESOLVED: Accept proposal
    <fantasai> miriam: This allows us to republish
    <fantasai> RESOLVED: Republish css-cascade-5
  10. added a commit that references this issue on Nov 18, 2021
  11. added a commit that references this issue on Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions