Comments (8)
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 const {scopeId} = useScopedStyles$(...)
and then <Link class={scopeId} />
. This is the correct way to pass scopes down to Qwik Components.
from qwik.
This is in conflict with the docs: https://qwik.dev/docs/components/styles/#global-selector
The <Link class={something} />
is only for non scoped css according to the docs.
Using the ?inline
parameter on the style file import changes how the file is read (I'm assuming here) and therefor I can't use it in the same way.
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).
from qwik.
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
from qwik.
Ok, I finally found a solution. The hint with the nested stuff was essential:
Instead of:
ul {
color: green;
> :global(a) {
color: red;
}
}
I have to write this:
ul {
color: green;
}
ul > :global(a) {
color: red;
}
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.
from qwik.
Ok, I think I have to revert my last comment... It worked in one scenario and doesn't in another.
It works if the global is added to an element which already is tracked. Example:
this works:
nav:global(.open) {
display: block;
}
this doesn't:
nav :global(a) {
display: block;
}
Reason seams to be that the first example only adds the .open
via JS to an element which has a scoped class already and the second doesn't.
The first one results in something like this: nav.open.⭐️rwl3jt-0 {
while the second one creates something like this: nav.⭐️rwl3jt-0 a.⭐️rwl3jt-0 {
which doesn't work since the .⭐️rwl3jt-0
doesn't exist on the a tag which still comes from the Link component.
from qwik.
Related Issues (20)
- [🐞] Error: Missing Qwik City Env Data HOT 11
- [🐞] <Resource> passed as prop does not render in correct position HOT 1
- [✨] Improve Runtime performance and Memory Footprint HOT 2
- [🐞] The behaviour of the cache has changed 1.5.0 (cloudflare) HOT 13
- [🐞] Stores without writers don't get serialized HOT 9
- [🐞] Failed Cloud Run Deployment after `npm run qwik add cloud-run` HOT 4
- [🐞] Cookie not set when using `$server` HOT 2
- [🐞] Error with TailwindCSS 4 when used in Qwik HOT 4
- [🐞] onClick$ not always fired HOT 2
- [🐞] SPA resume (probably) needs to be fixed for upcoming v2 changes HOT 5
- [🐞] qwik-city: vite base doesn't work in dev mode HOT 4
- [🐞] requestEvent.url.hash is always the empty string, even when the URL contains a hash HOT 1
- [🐞]icons not working in production or in preview mode HOT 1
- [🐞] Qwik server crashes when entering multiple slashes at the end of a home route
- [🐞] Sitemap is not generating / finding routes when using localized routing HOT 1
- [✅] The Edge Function "_qwik-city" is referencing unsupported modules HOT 1
- [🐞] Qwik Insights returns 500 error for fetching data/strategy HOT 3
- [🐞] Invalid module "@qwik-city-plan" is not a valid package name imported from HOT 12
- Code split loading[🐞] HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qwik.