SSR Theme Switching Without Flash in SvelteKit

How to implement theme switching that avoids flash when users prefer the opposite of their system theme