Re: [csswg-drafts] [CSS Import Once] @import-once, or some syntax for importing a stylesheet only once (#6130)

> Using layers as a workaround is by far not the ideal dev experience.

I don't see layers as a workaround but the canonical solution, unless I see a use case where layer-based solutions are fundamentally broken.

And layers are not global. With concepts like sublayers and layered imports, layers work pretty much the same way as modules. For example:

```css
/* base.css */
@layer a { ... }
@layer b { ... }
```

```css
/* main.css */
@import url('base.css') layer base;
@layer my-own-business { ... }
```

The styles in `base.css` are imported into layers `base.a` and `base.b`, with the "global" namespace untouched. And you can have another library using `main.css` by importing it into another layer (say `main`), and then everything goes into layers named `main.*`.

In fact, there's no such a thing as a global layer namespace -- you can always import things into another layer.

---

Btw there are still open issues where CSS modules and layers don't work well with each other (like #7002). They still seem fixable within the scope of layers, though.


-- 
GitHub Notification of comment by xiaochengh
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6130#issuecomment-1970856426 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 29 February 2024 10:38:34 UTC