mode-watcher needs a little setup: you mount its <ModeWatcher /> component once, and it reads localStorage and applies the mode
to the global <html> element — adding a
dark class and setting color-scheme. This site drives its own theme off a
data-theme attribute, so the two coexist without collision.
Mount it once, then any button can drive the mode:
toggleMode, setMode, and resetMode drive the global theme; the
mode, userPrefersMode, and systemPrefersMode runes report the current state.
SSR-friendly theme, no flash
mode-watcher only persists to localStorage, which the server can't read — so on its own the first paint can flash. The bar above fixes that: the island mirrors
the resolved mode into a cookie, serverProps
reads it back into <ModeWatcher defaultMode>, and a transformPage hook stamps
class="dark" onto <html> before the response is sent. Pick a mode, then reload — the page comes back correct with no flicker (server sent:
shows the value the server used).
"system" can't be server-resolved without JS, so the cookie stores the resolved
light/dark.
```
### ModeControls.svelte
```svelte
SSR themeserver-rendered from a cookie — no flash on reload