question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

Describe the bug

  1. I have the main $layout.svelte and a $layout.reset.svelte for /admin path
  2. In $layout.svelte, we declare some <style> or import some stylesheet import ../../../*.css or ../../../*.scss.
  3. In $layout.reset.svelte, we declare same <style> or import some stylesheet import ../../../*.css or ../../../*.scss.
  4. When we open http://localhost:3000/admin,
  5. In svelte-kit dev, both <style> from $layout.svelte and <style> from $layout.reset.svelte are applied.
  6. In svelte-kit build output, both <link href="layout.css"> and <link href="$layout.reset.css"> are applied.
  7. Main Issue is, both Styles are applied even if we have reset the layout.
  8. 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 :

Screenshot 2021-04-18 at 5 57 29 PM

svelte-kit build output :

Screenshot 2021-04-18 at 5 59 23 PM

Logs No Logs.

To Reproduce

  1. Create new SvelteKit project.
  2. Create a $layout.svelte at the root of routes folder
  3. Create a $layout.reset.svelte at any sub route (e.g /admin).
  4. Add <style> or import some style file in both $layout.svelte and $layout.reset.svelte.
  5. Check different behaviours of svelte-kit dev and svelte-kit build.

or

Reproduction Repo : https://github.com/DhyeyMoliya/sveltekit-css-issue

  1. main branch for <style> example
  2. style-import branch from import ../../*.css example

Expected behavior

  1. It should apply CSS (<style> or import "../../*.css" or "../../*.scss") from $layout.reset.svelte only.
  2. Style from $layout.svelte should not be included in the output of a reset route (eg. /admin in this case).
  3. 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tylerbrostromcommented, Apr 29, 2021

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.

0reactions
DhyeyMoliyacommented, May 7, 2021

It seems there is no solution to this problem for now. Closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FOUC happening in production when using __layout.reset ...
svelte and resolved it by importing the main css file, in my case app.css, into the reset layout file. This kinda struck me...
Read more >
Why __layout.reset.svelte doesn't unload imported CSS files ...
I tried a workaround and it works, by importing that CSS file inside /src/routes/index.svelte . It works because my root app is in...
Read more >
How to reset a layout in svelte/kit with vite - Stack Overflow
If I have a main layout "+layout. svelte" at /routes and then try to reset the layout at /routes/auth/login It is not working....
Read more >
How to use Tailwind CSS with Svelte - LogRocket Blog
Create beautiful, custom components with Tailwind CSS to style your Svelte app using this step-by-step tutorial.
Read more >
Using CSS-in-JS with Svelte
But Svelte's style handling does have some limitations. It's too difficult to share styles between components, or apply app-level optimisations.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found