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

Add proposal for @sheet to enable multiple stylesheets per file #931

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

aluhrs13
Copy link
Contributor

@aluhrs13 aluhrs13 commented Jan 9, 2025

As part of looking at Declarative CSS Modules, TAG has suggested that we should investigate @sheet as a possible direction. This explainer summarizes and builds on the CSSWG discussion about this idea to consolidate it into a single location.

AtSheet/explainer.md Outdated Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved
[SameObject] readonly attribute StyleSheetList nestedStyleSheets;
};
```
*Open issue: The name `nestedStyleSheets` is up for discussion*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe namedStyleSheets?

AtSheet/explainer.md Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved
AtSheet/explainer.md Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved
AtSheet/explainer.md Show resolved Hide resolved
AtSheet/explainer.md Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved
AtSheet/explainer.md Outdated Show resolved Hide resolved

```html
<style>
/* The following two imports should only make a single network request. */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: these are missing indentation

readonly attribute DOMString? name;
};
```
*Open issue:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be here?

1. Whether rules are applied automatically for `@sheet` definitions, or whether they need to be imported to apply. The CSS Working Group did not have a consensus.
2. Fragment-only identifiers (without a URL) should allow inline `@sheet` references on the same document to be included globally (even within shadow roots). This wasn't brought up in the CSSWG discussions at all, but is important for DSD without requiring an external file (to avoid FOUC).
3. Behavior of `@import` - should `@import` be possible within `@sheet` at all, should it be allowed if it's the first/only statement, or should it be blocked? There was discussion of this in the CSSWG, but no conclusion was reached. This was briefly discussed in this CSSWG conversation: https://lists.w3.org/Archives/Public/www-style/2023Apr/0004.html
4. What happens with multiple `@sheet` definitions with the same identifier? First-definition wins, or do they get merged like `@layer`? Again, this was brought up in the CSSWG but not resolved. Note that it's possible to have a "Flash of other-styled content" if it's last-defintion-wins, as the first definition may apply, then a later definition from an external CSS file may override it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we link to where this was brought up in the CSSWG?

AtSheet/explainer.md Show resolved Hide resolved
<span>I'm in the light DOM</span>
```
6. The name `nestedStyleSheets` is up for discussion.
7. Should we add `name` to the `StyleSheet` interface or overload the existing `title` attribute instead?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra space before "overload"


sheet.css:

```html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```html
```css

sheet.css:

```html
@sheet foo {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CSS here doesn't seem to be valid. Was it meant to be this?

@sheet foo {
  div {
    color: red;
  }
}
div {
  color: blue;
}

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

Successfully merging this pull request may close these issues.

5 participants