import { darkMode } from "../store"; import { isLoading, waitLocale } from 'svelte-i18n" /> import { darkMode } from "../store"; import { isLoading, waitLocale } from 'svelte-i18n" /> import { darkMode } from "../store"; import { isLoading, waitLocale } from 'svelte-i18n"/>

Sapper - add .mode-dark to document during SSR

46 Views Asked by At

Given basic _layout.svelte component

<script context="module">
  import { darkMode } from "../store";
  import { isLoading, waitLocale } from 'svelte-i18n';

  export async function preload(page) {
    darkMode.set(getCookie("isDark") || window.matchMedia("(prefers-color-scheme: dark)").matches);
    return waitLocale();
  }
</script>

I have two questions:

  1. why preload in layout doesn't run even if I just add the only console.log inside
  2. how to add class '.mode-dark' to the document on the server-side? document is undefined
0

There are 0 best solutions below