-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[🐞] useStylesScoped$ doesn't support nested CSS #6011
Comments
Ok so the problem seems to be nested CSS not being supported by the scoped styles. The original CSS (in a .module.css) is ul {
color: green;
> :global(a) {
color: red;
}
} During dev, the resulting CSS is ul.⭐️d907jw-0 {
color: green;
> a {
color: red;
}
} Note that this is nested CSS, and that Chrome supports this, but the scoped styles don't support it. And in prod, it becomes ul.⭐️d907jw-0 {
color: green
}
ul.⭐️d907jw-0>a.⭐️d907jw-0 {
color: red
} Here, the nested rules are flattened, and the scoped styles correctly add the scoped classes. So, it's a bug, but only because it should also not be red in dev mode. To get the Link to be red, you have to do |
This is in conflict with the docs: https://qwik.dev/docs/components/styles/#global-selector So what is the correct way to handle scoped css? And even better would be to know how to use scoped scss (but we can ignore that for the moment if it makes things way to complicated). |
TBH I think the best way to style is using Tailwind (or UnoCSS). And to style Qwik components it's best to use the scopeId. But the behavior of global is a bug |
Ok, I finally found a solution. The hint with the nested stuff was essential: Instead of:
I have to write this:
I think the qwikest way to improve the issue would be to update the docs to remove the nesting there. But still, the bug should be fixed. |
Ok, I think I have to revert my last comment... It worked in one scenario and doesn't in another. this works:
this doesn't:
Reason seams to be that the first example only adds the |
Ideally, someone makes a PR that fixes nested global handling in dev |
After reading the doc, I want to say thank you everything. I am highly interested in solving the problem/issue, but I need help in understanding.
Please bear with me if this can be a beginner issue, I am completely new to this space, and it may take some time to solve. |
So this seems to be the cause of #6982. My problem is that Qwik is un-nesting |
@brandonpittman only 87% of browsers supports nested CSS right now, so IMHO the correct behavior is to unnest, but then correctly. |
@wmertens This feature is newer than even nesting, but it's a progressive enhancement. If it doesn't work, I don't mind. Qwik is doing too much here. This un-nesting behavior should be left to something like PostCSS. But even if it un-nested it, if Qwik appended the scope ID to the stuff that it nested, things would still work. |
Unfortunately the CSS can't be processed by post css, the optimizer can't do it. But indeed it's a bug and it should add the scope correctly. |
...or indeed leave it alone |
Seems like the easiest solution. |
Which component is affected?
Qwik Runtime
Describe the bug
I have a simple qwik project with qwik city.
I use scoped styles with useStylesScoped$.
I'm styling the
Link
component via the :global() selector.In development all is fine. After deployment I noticed all the :global() styles are missing.
I use the node deployment with the entry.server.js.
I investigated a bit and found out that if I start the app via the terminal with
yarn start
(after a successful build) all is fine, but if I start the same build via a node command (which I have to do for my specific deployment environment) the :global() styles are all gone.I have a entry.cjs file to then just import the entry.express.js
Like so:
With that setup (local and on the hosting provider) I get the same broken result.
Reproduction
https://github.com/netzpixel/qwik-broken-global-example
Steps to reproduce
npm install´
npm run dev`open the page
check the color of the first link (Docs) -> should be red
stop the running process
node entry.cjs
open the page
check the color of the first link (Docs) -> it's not red anymore
System Info
Additional Information
The system seams to be unrelated. The same happens on a linux server.
The text was updated successfully, but these errors were encountered: