-
Notifications
You must be signed in to change notification settings - Fork 164
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
feat: global CSS loader #10036
feat: global CSS loader #10036
Conversation
Closes #9970
If this gets merged, some documentation probably needs to be added to the docs repo about this. |
I just tested this snapshot ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried, it works as described, great job!
One thing I think could be improved is that when using import styles from './main-view.css';
, I only see a warning when trying to use styles, and it doesn't tell what to do.
First, could we show the deprecation warning for the import line instead of when trying to use styles?
Then could it have more information like xxx is deprecated, please use xxx.shadow.css instead
?
I'm not sure if this is somehow possible. I can try if adding a note to the deprecation comment in types.d.ts shows it as a deprecation message. That's a good idea if we can show that you should use the shadow suffix instead. |
TeamCity build failed probably due to the scheduled service outage. Let's retry the build a bit later. |
After trying alternatives locally, I ended up preferring query strings to determine how a file is loaded, instead of the filename. That way, the user can determine in each case how they want to load a file. For example, let's say someone has a small If the filename determines how the file is loaded, the person in the above example would need to create two files with the same content to achieve their use case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to use filename convention over URL suffixes based on the reasons below:
CSS contents are never independent of their usage, but are rather always bound to some area of the application. The context of usage needs to be defined already when creating a CSS file, at least in the author’s mind — it is essential to know which selectors to use.
When you have a separate CSS file, and the file path does not tell whether it is applied to shadow roots or document styles, it’s a DX issue.
It is even more important for the future maintainer to be able to tell what CSS was for. Consider using a global file content search when maintaining CSS in a large project (often the only tool available). Filename convention makes it easier to confine the search in the certain type of CSS (only shadow or only document).
CSS for both document and shadow roots is an anti-pattern that should be avoided. It never yields efficient and maintainable CSS, unless you really know that you’re building a custom design system.
This makes it so that you can import a CSS file into document scope with an import like:
(using a
*.global.css
filename suffix)instead of needing something like:
It also makes it so that using a
CssResult
imported like:will show a deprecation warning (based on an update to
types.d.ts
).To avoid the deprecation and future proof your import you need to use a filename suffix
*.shadow.css
when you need to import a CSS file as aCssResult
like this:It's intended that in the next major version (after this has been released) the default behaviour for
*.css
will change so that you no longer need the.global.css
suffix to import styles to document scope but keeping global in the filename will still keep working.Closes #9970