-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
HMR - Inlined css reports as page it was imported on and not as itself #232
Comments
Problem is appearing in Vite API |
Hi, can you explain the reason you're using the |
It's basic use is in switching themes with css files and with $theme store var. I make css var reactive to $theme var change. Importing css files without inline suffix loads all csses into dom and as far as I'm concerned in order of importing - so changes to first css are overwritten by 2nd even with correct hmr of first one. One perk of having inlined css is that you can store name of theme in css filename and automatically change theme by editing css and listening via This way csses edits and $theme var become synchronized and allow for quicker developing of different layouts. |
Thanks for the explanation. It still seems to me that this issue is intended behaviour from Vite side, unless they plan to publicise |
Hmm, adding style nodes to the component template like this isn't ideal. Wouldn't style props help to build themable components that react to changes? https://svelte.dev/docs#template-syntax-component-directives---style-props Or just some service/helper that updates them in a generated style node with :root if this is about theming |
@dominikg I work on rather edge case b/c i test layouts of different sites in one frontend code base. I find having one main css file per theme/layout and then have more specific styles in each component as more clear to think about and to apply changes, be it small or overhauling. Using one css file allows me to edit all necessary classes in one go instead of switching to each component and doing edits in it's @bluwy The example from stackblitz is doing closest to what i seek. Even without bugs you mentioned being fixed,
Hard coding path to style is sufficient in my case, so there is no big need for pushing vitejs/vite#5940. Thanks for posting this solution. |
glad there is something that works for you. Closing the issue as the described behavior is "working as intended" from our perspective . Maybe you could also use svelte-preprocess external files feature to keep the css in a separate file and still benefit from scoping https://github.com/sveltejs/svelte-preprocess#external-files vite-plugin-svelte/packages/e2e-tests/svelte-preprocess/src/lib/multifile/MultiFile.svelte Line 5 in db84946
|
I would be cautious using |
Describe the bug
When inline importing css
import front from "./front.css?inline"
And editing it, HMR reports edit of .svelte file where it was imported.
[vite] hmr update /src/routes/index.svelte (x3)
Reproduction
Install:
https://github.com/ambrt/inline-css-bug-vite
npm run dev
Go to
front.css
and edit or just save.HMR should report
front.css
as being edited but its reportingindex.svelte
(Additionally there's alert on running page with Vite API data)
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: