79337802

Date: 2025-01-08 02:01:17
Score: 1.5
Natty:
Report link

Removing @import 'sanitize.css'; from the <style> tag and adding import 'sanitize.css'; to the <script> tag resolves the issue.

I came to this solution when reading the "Where should I put my global styles?" section of the FAQ for vite-plugin-svelte

This pointed out three issues with my original +layout.svelte file:

  1. Global styles should always be placed in their own stylesheet files whenever possible, and not in a Svelte component's tag

  2. The stylesheet files can then be imported directly in JS and take advantage of Vite's own style processing.

  3. The global attribute in my <style> tag is a feature from svelte-preprocess, which I was not using or had plans to use. If I were to use global styles in the <style> tag I should instead use the nested :global { ... } syntax, which not is recommended for global styles.

The fixed +layout.svelte looks like this:

<script lang="ts">
    import 'sanitize.css';
    let { children } = $props();
</script>

{@render children()}
Reasons:
  • Blacklisted phrase (1.5): Where should I
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Matthew Moran