-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Describe the bug
Editing CSS Module files that are imported in .svelte components causes a full page reload, while hot-reloading is expected (and demonstrably possible, but more on that in the "Additional information" section).
Before somebody asks "why aren't you using the <style> tag directly in your Svelte components and taking advantage of Svelte's built-in CSS scoping?", because they are not good enough, and I'm not alone in thinking that.
Reproduction
- Clone https://github.com/aradalvand/sveltekit-hmr-css-test
- Run
pnpm install - Run
pnpm run dev - Go to the
src/lib/Button.module.cssfile, and change thebackground-colortoblue. - Save the file.
- Notice how a full page reload is triggered in the browser
Logs
No response
System Info
System:
OS: Linux 5.15 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
Memory: 7.21 GB / 11.63 GB
Container: Yes
Shell: 3.6.1 - /home/linuxbrew/.linuxbrew/bin/fish
Binaries:
Node: 20.6.0 - /home/linuxbrew/.linuxbrew/bin/node
npm: 9.8.1 - /home/linuxbrew/.linuxbrew/bin/npm
pnpm: 8.7.1 - /home/linuxbrew/.linuxbrew/bin/pnpm
npmPackages:
@sveltejs/adapter-auto: ^2.0.0 => 2.1.0
@sveltejs/kit: ^1.20.4 => 1.26.0
svelte: ^4.0.5 => 4.2.2
vite: ^4.4.2 => 4.5.0Severity
annoyance
Additional Information
- Put the following code in the
<script>section of your root+layout.sveltefile (or, in the repro app linked above, it could be in the+page.sveltefile):
if (import.meta.hot) {
import.meta.hot.on('vite:beforeFullReload', () => {
throw '(skipping full reload)';
});
}- Make a change to the
Button.module.cssfile again (change thebackground-colorback tored), and save the file. - At this point, if you look at the browser console, you'll see
Uncaught (in promise) (skipping full reload), as expected; the full page reload is prevented. - Now, make a meaningful change (not just whitespace, change the button's label for example) to the
Button.sveltefile, and then save the file. - Back to the browser, you can see that the new CSS change has been hot-reloaded as well. I think this showcases that HMR for these CSS files is perfectly possible, so this has to be a matter of misconfiguration or something similar on the part of SvelteKit.
Let me know. Thanks.
TheFireBlast, john-michael-murphy, xamir82, ekhaled and aradalvand