A user picks dark mode, reloads, and sees a white page for a moment before it turns dark. The server can't read localStorage , so it renders the default theme, and any code that waits for React runs after the browser has already painted that default.
This post builds a light / dark / system toggle with no theme library, then checks the first paint with Playwright. I tested everything on Next.js 16.4.6, React 19.3.0 and Tailwind CSS 4.3.3 , on a production build ( next build && next start ) unless I say otherwise.
1. Point Tailwind's dark: variant at a class
By default, Tailwind's dark: variant follows the prefers-color-scheme media query. A manual toggle needs it to follow a class instead.…