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:
Global styles should always be placed in their own stylesheet files whenever possible, and not in a Svelte component's tag
The stylesheet files can then be imported directly in JS and take advantage of Vite's own style processing.
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()}