Imported/Declared CSS from $layout.svelte is not ignored with $layout.reset.svelte. Dev and Build include different CSS <link> in different order
See original GitHub issueDescribe the bug
- I have the main
$layout.svelte
and a$layout.reset.svelte
for/admin
path - In
$layout.svelte
, we declare some<style>
or import some stylesheetimport ../../../*.css or ../../../*.scss
. - In
$layout.reset.svelte
, we declare same<style>
or import some stylesheetimport ../../../*.css or ../../../*.scss
. - When we open
http://localhost:3000/admin
, - In
svelte-kit dev
, both<style>
from$layout.svelte
and<style>
from$layout.reset.svelte
are applied. - In
svelte-kit build
output, both<link href="layout.css">
and<link href="$layout.reset.css">
are applied. - Main Issue is, both Styles are applied even if we have
reset
the layout. - Another Issue is, in
build
output’s<head>
tag,<link href="$layout.reset.css">
is preceded by<link href="layout.css">
, resulting in an output where style from$layout.svelte
are applied instead of$layout.reset.svelte
after build. Because of the declaration order of CSS.
svelte-kit dev
output :
svelte-kit build
output :
Logs No Logs.
To Reproduce
- Create new SvelteKit project.
- Create a
$layout.svelte
at the root ofroutes
folder - Create a
$layout.reset.svelte
at any sub route (e.g /admin). - Add <style> or import some style file in both
$layout.svelte
and$layout.reset.svelte
. - Check different behaviours of
svelte-kit dev
andsvelte-kit build
.
or
Reproduction Repo : https://github.com/DhyeyMoliya/sveltekit-css-issue
main
branch for<style>
examplestyle-import
branch fromimport ../../*.css
example
Expected behavior
- It should apply CSS (
<style>
orimport "../../*.css" or "../../*.scss"
) from$layout.reset.svelte
only. - Style from
$layout.svelte
should not be included in the output of a reset route (eg./admin
in this case). - Order of CSS
<link>
declaration should be correct.
Information about your SvelteKit Installation:
Diagnostics
-
The output of
npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite --binaries --browsers
System: OS: macOS 11.2.3 CPU: (8) x64 Apple M1 Memory: 35.38 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.4 - /usr/local/bin/node npm: 7.6.0 - /usr/local/bin/npm Watchman: 4.9.0 - /opt/homebrew/bin/watchman Browsers: Chrome: 89.0.4389.128 Edge: 89.0.774.76 Safari: 14.0.3 npmPackages: @sveltejs/kit: next => 1.0.0-next.78 svelte: ^3.29.0 => 3.37.0 vite: ^2.1.0 => 2.1.5 -
Your browser Edge
-
Your adapter (e.g. Node, static, Vercel, Begin, etc…) @sveltejs/adapter-node@1.0.0-next.14
Severity
How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of SvelteKit entirely?
Issue 1 - Severe - The build
output and dev
should give same outputs.
Issue 2 - Normal - Only the correct css should be applied
Note: the more honest and specific you are here the more we will take you seriously.
Additional context I’m happy to give more explanation. A SvelteKit REPL would really help in raising issues with examples.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top GitHub Comments
Can also confirm that stylesheets imported into the root
$layout.svelte
are present from routes with an associated$layout.reset.svelte
.Expectation is that module side-effects such as this would also be removed for routes with an associated
$layout.reset.svelte
.It seems there is no solution to this problem for now. Closing this issue.