qwik
qwik copied to clipboard
[Bug] scss with Qwik starter and ssr is broken
Qwik Version
v0.0.34
Operating System (or Browser)
macOs + Chrome
Node Version (if applicable)
No response
Which component is affected?
Qwik Rollup / Vite plugin
Expected Behaviour
scss styles loaded correctly
Actual Behaviour
-
npm init qwik@latest
- Choose Starter, Express and add Prettier
-
cd qwik-app
-
npm install
-
npm install sass
<-- UPDATE - add .mytitle { color: red; } inside global.css
- add
mytitle
class to h1 selector insideapp.tsx
- rename global.css to global.scss
- fix global.css import inside root.tsx
- run
npm run dev.ssr
andmytitle
class is not loaded
Additional Information
With npm run dev
is working correctly
Glenn from Discord here. :wave:
Looks like this might be a vite thing?
Does running npm add -D sass
help?
Ah. Got it working by running that command and importing the styles in my layout instead of the root.tsx and using useStyles$ inside of the layout component.
import { component$, useStyles$ } from '@builder.io/qwik';
import styles from "../global.scss"
export default component$(() => {
useStyles$(styles);
return ...
});
sorry, I miss to report this step. I did also npm install sass
after step number 4
I will update the main message
Cool. Let me know if moving that import and using useStyles unblocks you.
Yep, I added useStyle directly inside my App component and now works correctly
....
import styles from '../../global.scss';
export const App = component$(() => {
useStyles$(styles);
....
});
is it the right way to manage scss inside Qwik?
I don't think it's the right way. It's not the wrong way either. Loading from the root.tsx should work, so I'm pretty sure this bug or something that should be documented if it's not.
But at least we found a work-around so you can keep working. :+1:
It's also a vite thing, but when using useStyle$()
it's good to import css or scss using ?inline
like this:
import styles from '../../global.scss?inline';
export const App = component$(() => {
useStyles$(styles);
....
})
Otherwise vite will generate global styles, and extra .css files, in effect loading the css twice. Not very happy with this... but i cant find a better way in Vite yet
I'm facing a similar issue, and it is randomly happening... I'm trying to import bootstrap files inside my own .scss file. Sometimes an error is raised [plugin:vite:css] [sass] Undefined variable
. You have to refresh a few times to see this error happen, as if imported .scss files are not loaded in the correct order. I'm able to reproduce in the following stackblitz
It's also a vite thing, but when using
useStyle$()
it's good to import css or scss using?inline
like this:import styles from '../../global.scss?inline'; export const App = component$(() => { useStyles$(styles); .... })
Otherwise vite will generate global styles, and extra .css files, in effect loading the css twice. Not very happy with this... but i cant find a better way in Vite yet
I'm not sure it's a vite thing... because the problem doesn't appear when using Sass with Vite, and without qwik plugins.
is this still a problem with latest?
is this still a problem with latest?
I have upgraded all my project dependencies to latest versions, including latest from qwik and from vitejs. I don't see any issue anymore. Thanks !
@omarbelkhodja nice! would you mind to close the issue? 🙏
Sorry guys... The issue appeared again. It is very random. It is like it worked without any problem during a few days, then it reappeared again. Sometimes, it is like no problem during the first startup, but when hot reload happens, the issue appears.
The new issues is probably different and worths a new issue reproduction! i am gonna close this issue, but we should open a new one with a new repo case if in some cases it does not work.