DEV Community

Discussion on: Persistent Theme Switch (Dark mode) with Svelte (SvelteKit) & Tailwind

Collapse
 
willkre profile image
Will • Edited

Hey @vitroidfpv thanks! You may notice that dependent on what your device theme is set to and what you have set in local storage, when you load the page it "flashes" to the other color right after the initial load (i.e. you can see the background transition from white to black or vice versa).

You can actually see it on the last GIF in the guide when I refresh a second time on the black background. The page refreshes showing an initial white background, then the <ThemeSwitch /> renders a split second later and applies the dark mode styles.

There are a few ways to avoid this, one easy way is to just check & apply the theme in the <script> tag within app.html so that it's applied before the content loads.

I've just updated my template to include it, feel free to check it out here